Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

display list of days in a week in Rails using Date::DAYNAMES

I'm having trouble displaying a list of days in a week in a form.

<%= form_for [@hourable, @hour] do |f| %>

  <% days = []
  Date::DAYNAMES.each_with_index { |x, i| days << [x, i] } %>

  <% days.each_with_index do |day,index| %>

  <div class="field">
    <%= f.check_box day[0] %>
  </div>

  <% end %>   

  <div class="actions">
    <%= f.submit %>
  </div>
<% end %>

I'm getting error

undefined method `Sunday' for #<Hour:0x007fe13c764010>

But if I just display

<%= day[0] %>, it will give me a list Sunday, Monday, Tuesday, etc... to Saturday

What am I doing wrong here?

Thanks

like image 886
hellomello Avatar asked Jun 26 '13 03:06

hellomello


1 Answers

Replace

<% days = []
 Date::DAYNAMES.each_with_index { |x, i| days << [x, i] } %>

<% days.each_with_index do |day,index| %>

<div class="field">
 <%= f.check_box day[0] %>
</div>

With

 <%= f.label :FIELD_NAME%>
<% Date::DAYNAMES.each do |day| %>
  <%= f.check_box :FIELD_NAME, {}, day %>
  <%= day %>
<% end %>
like image 115
Muntasim Avatar answered Sep 21 '22 23:09

Muntasim