Just starting to work through my first Rails app, very new to Ruby,
still getting my head around the syntax, iterators, blocks, procs,
etc., and so of course I could use some assistance.
my basic question: is it possible to include a new iterator/block in
the block called by calendar() ? I assumed it would be possible, but
I’m having some trouble, so I’m wondering if it’s semantically
prohibited or some such. more generally, is it possible to run an
iterator inside an iterator?
I’m using the calendar_helper plugin, and I need to display all events
that are scheduled for a given day in the appropriate table cell. The
calendar() method is, I gather, an iterator which allows you to attach
a block, to which it will pass a Date object for each date in the given
month. I want to list all events that fall on the given date, so I’m
wondering if it’s possible to iterate through my list of events (in the
middle of the calendar() call) and list all matches. Yes, that’s
correct, I want to iterate through the entire list of events many
times, ONCE FOR EACH DAY OF THE MONTH, searching for matches.
I realize it’d be much more efficient to use the controller to filter
out all events that won’t be displayed in the given monthly view, and
sort the remaining relevant events in a easily accessible hash or
array. But just for the sake of argument, is it even possible to do it
the other way?
I’ll paste some code, as my syntactical ignorance might have something
to do with it.
<%= calendar(:year => 2006, :month => 8) do |d|
@events.each { |e|
if e.date.eql?(d)
# list event
end }
end %>
I’m getting an “undefined method `map’ for #Event:0x36eacdc”
thanks in advance for any help