0

I'm trying to iterate through an array defined in a model, to show all the days from the array, but I get this error.

"undefined local variable or method `day'"

I'm a newbie and I can't figure out how to fix it, so any help would be much appreciated.

schedule.rb

class Schedule < ApplicationRecord

  def self.days
    ['monday', 'tuesday', 'wednesday', 'thursday', 'friday', 'saturday', 'sunday']
  end

end

_form.html.erb

<% Schedule.days.each |day| %>
<h2><%= day.titleize %>: <%= Date.today.send(day) %></h2>
<% end %>

1 Answer 1

1

You forgot to add do

<% Schedule.days.each do |day| %>

Just fix the syntax and it should work.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.