List of Checkboxes

Hi,

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.

Sorry for the noob question.

Keith

The check_box helper in your view and a call to update_attributes in
your controller are all you need :slight_smile:

Cool, Didn’t know there was a checkbox helper.

Thanks for the answer.

Keith

Hi!

On Jan 30, 2007, at 14:43, Mick S. wrote:

The check_box helper in your view and a call to update_attributes in
your controller are all you need :slight_smile:

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).

Your sincerely,
Damian/Three-eyed Fish

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

in your view:
<% for section in @sections%>

<input type=“checkbox” id= “<%section.id%>” name=“section_ids[]”
value="<%=section.id%>"
<%if @content.sections.include? section %>
checked=“checked”
<%end%>

<%=section.name%>

<% end%>

in controller (new or create):
@content.sections= Section.find(@params[:section_ids]) if
@params[:section_ids]

hope this helps

george

On Tuesday 30 January 2007 12:24, Keith D. wrote:

Does anyone have a link or information on how to handle lists of
checkboxes in rails?

Try this plugin

http://www.agilewebdevelopment.com/plugins/multiple_select_helper

HTH,
Michael


Michael S.
mailto:[email protected]
http://www.schuerig.de/michael/

Thanks Michael,

Just tried it out and it does exactly what I was looking for and in good
rails
style it took about 5 minutes as well.

Keith

I just tend to use:

<%= check_box(“product”, “is_active”) %>

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:

http://wiki.rubyonrails.org/rails/pages/HowToUseCheckBoxes

On Jan 31, 2007, at 16:30, mr_robot wrote:

<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.

| Privacy Policy | Terms of Service | Remote Ruby Jobs