I have dining rooms and I have a type
field (Single, Double). I want to use the switch for this field. So, I use it as follows:
<% form_for(@room) do |f| %> <%= f.radio_button :type, "Single" %> <%= f.radio_button :type, "Double" %> <% end %>
This is great for editing. The problem is that for the new view, I want to switch to "Single" by default. For this code, the value is not checked for the new view.
Now I'm setting it up with a status check
<% form_for(@room) do |f| %> <%= f.radio_button :type, "Single", :checked => @room.new_or_single? %> <%= f.radio_button :type, "Double" %> <% end %>
Room model
def new_or_single? type.nil? or type == "Single" end
Is there a better way to achieve this?
source share