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 http://www.ruby-forum.com/.

--
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 rubyonrails-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/27339ce1b51bc7c4bf4563d4f4206107%40ruby-forum.com.
For more options, visit https://groups.google.com/groups/opt_out.

No comments:

Post a Comment