How do you set a custom id when using a check_box_tag helper in rails?
I have a loop which creates a bunch of checkboxes based on a collection:
- subject
This was very helpful and brought my days-long search to an end. Most of what I'd found until now contained syntax and extra parameters which rails either flagged or ignored altogether. All I want to do is pass an array from my view to my controller and use checkboxes to tell the controller which array elements to process. I was able to reduce the above even further, to:
<%= check_box_tag "c[]", c.id %>
where c comes from my database:
<%= @objects.each do |c| %>
This of course passes an array of object ids to my controller pertaining only to the checked entries (entries are unchecked by default since I left out the :false parameter, which by the way produces the same result as :true), which is almost all I need.
Now I just need to pass in an object type indicator - even just a literal string will do nicely - so that the controller knows what type of object it is to process without my having to augment my model with an extra column. I'll start in on that now and post my solution but please let me know if there's a quick and easy way to do this if you already know.