<%= form_for(@timetable) |f| %> <% timetable.all.each |t| %> <% if t.day == "monday" %> <%= f.select :day, options_for_select(%w[tuesday wednesday thursday friday saturday sunday]) %> <% elsif t.day == "tuesday" %> <%= f.select :day, options_for_select(%w[wednesday thursday friday saturday sunday]) %> <% elsif t.day == "wednesday" %> <%= f.select :day, options_for_select(%w[thursday friday saturday sunday]) %> <% elsif t.day == "thursday" %> <%= f.select :day, options_for_select(%w[friday saturday sunday]) %> <% elsif t.day == "friday" %> <%= f.select :day, options_for_select(%w[saturday sunday]) %> <% elsif t.day == "saturday" %> <%= f.select :day, options_for_select(%w[sunday]) %> <% else %> <%= f.select :day, options_for_select(%w[monday tuesday wednesday thursday friday saturday sunday]) %> <% end %> <% end %> <% end %>
if value "monday" exits in database field "day" value "monday" should not appear in select options. there other efficient way this?
got answer
<% @values = ["monday", "tuesday", "wednesday", "thursday", "friday", "saturday", "sunday"] %> <%= f.select :day, options_for_select(@values - timetable.pluck(:day)) %>
<% values = ["monday", "tuesday", "wednesday", "thursday", "friday", "saturday", "sunday"] %> <%# timetable.all.each |t| %> <%= f.select :day, options_for_select(values - [@timetable.day], selected: @timetable.day ) %> <%# end %>
i comment out looping there showing multiple select box.
Comments
Post a Comment