Ivor P. wrote:
If I understand you correctly, then in your controller you would like an
array of the checked items which you will access from params.
I have recently done this for assigning roles to users:
My controller action looked like this:
def assign_roles
user_roles = params[:role]
user_roles.each do |job|
UserRole.create(:user_id => params[:user_id], :role_id =>
job.to_i)
end
redirect_to ‘somewhere else’
end
The value is only returned if the checkbox is checked so you get an
array of
all the checked id’s.
Thanks Ivor,
i got the method right but am wondering what is happening when i do
this:
My view has this
<%form_tag :action=>‘selected’ do%>
<%for result in @results%>
<check_box_tag “result[]”,result.id,checked=false%> |
<%end%>
<%end%>
And the in the controller i have this method
def selected
@selected_items=params[:result]
end
The selected.rhtml
<%[email protected]%>
however i get a blank page. but when i inspect the logs i see that the
parameters were posted.
how do i get the checked ids rendered or displayed to the user?
Thanks