Have a look at this page, at the "gotcha" around multiple => true.
http://apidock.com/rails/ActionView/Helpers/FormHelper/check_box#note_info-1001
Walter
On Sep 30, 2013, at 7:16 AM, Jon Goodey wrote:
> 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
> To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
> 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.
--
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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To view this discussion on the web visit
https://groups.google.com/d/msgid/rubyonrails-talk/5B138B0B-F545-4E5D-B093-73EC7EC5D5C2%40wdstudio.com.
For more options, visit https://groups.google.com/groups/opt_out.