Does anyone have a link or information on how to handle lists of
checkboxes
in rails?
I am working on a property site and each property has a list of features
which are rendered as
a list of checkboxes. I am trying to figure out how to handle which ones
are
checked and which not
and persist them back to the database.
The check_box helper in your view and a call to update_attributes in
your controller are all you need
Could you please give me the example of using the checkbox helper?
I need to show a list of tags so that tags belonging to the page are
checked. I’m bewildered with “method” parameter — it should be a string
and I don’t know how to write it if I want to call @page.includes?(topic).
hi damian
i recently did a similar thing, so here’s maybe what you are looking
for - it may not be the best or most elegant way - i didn’t use
checkbox helper, because i couldn’t get it going properly - i’m still
a newbie, but this works
where “product” is an AR object stored in @product, and “is_active” is a
column name of type boolean (if the method is a string, it is taken to
be an AR column name).
Further information can be found in the Rails wiki:
<input type=“checkbox” id= “<%section.id%>” name=“section_ids[]”
in controller (new or create):
@content.sections= Section.find(@params[:section_ids]) if @params[:section_ids]
hope this helps
george
Thank you very much!
This is an approach I’m using now, I just wanted to see whether I can
write less code. I’m thinking of writing my own helper for it, but as
I’m a newbie, I should find out how to do it.
Yours sincerely,
Damian/Three-eyed Fish
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.