Hi all,
I’m building a site based on the middleman-starter-netlify-cms example on Github. The problem is that I’m getting errors when using select
method on my data. Basically, I want to post only the future events on the homepage with the inline ruby below :
<%= data.events.select { |e| e[1].date.future? }%>
But I get:
NoMethodError at /
`## undefined method `date' for "n":String`
However, sort
method used in the example code works pretty fine:
<% data.events.sort {|a,b| b[1].date <=> a[1].date}.first(3).each do | event | %>
<%= partial 'partials/events/event', locals: {event: event[1]} %>
<% end %>
I thought select
works with any enumerable, hash or array. What am I missing here?
Here is my event collection on the config.yml
collections:
- name: event
label: Event
format: yml
extension: yml
folder: data/events/
create: true
slug: '{{title}}'
fields:
- {label: Title, name: title, widget: string, required: true}
- {label: Publish Date, name: date, widget: datetime}
- {label: Image, name: image, widget: image, required: true}
- {label: Place, name: place, widget: string, required: true}
- {label: Time, name: time, widget: datetime, date_format: "DD.MM.YYYY", time_format: "HH:mm", required: true}
- {label: Body, name: body, widget: markdown }