I would do something like
check_box_tag(''books['' + book.id.to_s +
''][subscribed]'', ''whatever'',
book.subscribed)
But I''m relatively new so that might not be the best way.
This will results in hash that looks like
params[:books][0][:subscribed] => ''whatever''
if checked
-----Original Message-----
From: rails-bounces@lists.rubyonrails.org
[mailto:rails-bounces@lists.rubyonrails.org] On Behalf Of Jim Halberg
Sent: Monday, April 17, 2006 6:09 PM
To: rails@lists.rubyonrails.org
Subject: [Rails] check_box
I''ve got a question on the use of check_box.
***
This is working but there just has to be a better way:
RHTML:
<% for book in @books do %>
<tr>
<td><%=book.label%></td>
<td>
<%checked = book.subscribed ? ''checked'':
''nope''%>
<%=check_box("book" + book.id.to_s,
''checked'', :checked => checked)%>
</td>
</tr>
<% end %>
RB:
params["book" + book.id.to_s][''checked'']
**
I would much rather have something like this in the RHTML:
<% for book in @books do %>
<tr>
<td><%=book.label%></td>
<td>
<%=check_box(''book'',
''subscribed'')%>
</td>
</tr>
<% end %>
The issue I run into though is that the naming convention ends up
being the same for all of my books (since I am referring to them as
"book" when the check_box is created.
something like: <%=check_box(''book.label'',
''subscribed''%> results in
errors as well...
Like I said, the first block if working for me but... let me know of
any alternatives.
Thanks in advance
- Jim
_______________________________________________
Rails mailing list
Rails@lists.rubyonrails.org
http://lists.rubyonrails.org/mailman/listinfo/rails