Ruby on Rails Monday, September 30, 2013

A quick question I have working with a object in a rails 3 app and I
would like to retain the checkboxes ticked (for example there are 3
options if someone chooses option 1 and 2 and refreshes the page the
checkboxes 1 and 2 will remain ticked), this is very easy with radio
buttons but I am still trying to get my head around it with checkboxes.

here is some code:

<%= form_for(@user, :remote => true) do |f| %>

<%= f.check_box :a1, {:multiple => true}, "1", "" %>
<%= f.check_box :a1, {:multiple => true}, "2", "" %>
<%= f.check_box :a1, {:multiple => true}, "3", "" %>
<%= f.submit %>
<% end %>
<%= @user.a1.inspect %>
output from the inspect element:

"---\n- ''\n- '1'\n- ''\n- '2'\n- ''\n"
the user model has the a1 as a string in the db.

thanks in advance if anyone can help ,e

Regards Jon

Posted via

You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to
To post to this group, send email to
To view this discussion on the web visit
For more options, visit

No comments:

Post a Comment