I've got a HAML file which works:
%h2
#{@schedule_item.schedule_id}
and prints the ID.
I then try:
%h2
- @schedule_item.each do |test|
%li test
and get the error: undefined method `each' ScheduleItem:0x007ff8b91c06b0
can someone explain why I can't run each on this instance variable?
each
is a method that can be used on collection objects/Arrays
Although, i cannot see the reason you are iterating a single instance, however if you want to run each
on single instance, you need to first cast it as an array like this.
%h2
- Array(@schedule_item).each do |test|
%li test