I want to make a form based on check_boxes, and I want it to be checked, if '@clans' array is not nil and it contains a 'value' of a given checkbox.
My first atemnpt was:
<%= check_box_tag 'clans[]','Feniks', true if !@clans.nil? and @clans.include? 'Feniks' %>
but when @clans is nil, the check_box disappears, just like it was disabled.
I managed to solve it with code like that:
<% if !@clans.nil? and @clans.include? 'Feniks' %>
Feniks: <%= check_box_tag 'clans[]','Feniks', true %>
<% else %>
Feniks: <%= check_box_tag 'clans[]','Feniks' %>
<% end %>
but it looks so bad, that there have to be a better way to write this :)
Please show me how to handle this :)
Aucun commentaire:
Enregistrer un commentaire