Checkboxes across multiple objects

So I have a list of jobs which I show like this. (cleaned up..)

_list.rhtml <table> <% for job in @jobs %>

<tr><td><%= job.name %></td></tr>

<% end %>

I want checkboxes next to each and every job name and a button or link somewhere else on the page to "delete selected", "publish selected" , and "unpublish selected"

I have seen the RailsCast which does this, but it uses REST and I am not using REST and am confused.

Can anyone help?

I need the data of the checkboxes in the controller. Just not sure how to get it.

I am pretty sure I want something like this in the view. <td align="center"><%= check_box_tag "job_ids", job.id %></td>

But don't know what the form header or submit buttons should look like to get me the data in the controller.

    Reply Reply to author Forward

Hi,

You are right about the checkbox; it should look something like that. I believe the correct form is: <%= check_box("job_ids", jod.id) %> Then you just use an old school form(on top of my head): <%- form_tag :controller => 'foo', :action => 'bar' do -%> <%= check_box("job_ids", jod.id) %> <%= submit_tag("Go") <%- end -%> But I might be sadly mistaken. :wink:

With kind regards, Harm

Yea, not so much.

I need to then access the data in the controller.

And I want to be able to do different things to the data based on three different (Links or Submit Buttons)

Yea, not so much.

I need to then access the data in the controller.

But you can pull that from the params right? params[:job_ids] is an array of ids.

And I want to be able to do different things to the data based on three different (Links or Submit Buttons)

In that case you can look at the params[:commit] value.

Ok.

So I finally got that working.

Parameters: {"commit"=>"delete selected", "job_ids"=>["1632", "1633", "1634"], "action"=>"updateselected", "controller"=>"jobs"}

I can access the Ids no problem from the controller.

Now the only thing I would like to do is make these "links" instead of "submit buttons" to make the app look a little better.

I want to either have three links [Delete Selected, Publish Selected, UnPublish Selected]

Or do a Drop down like Gmail does for the actions availble when I select a bunch of emails.

Can anyone help with that?

Right now all I have in the view is

<%= submit_tag 'delete selected'%> <%= submit_tag 'publish selected'%> ...

Thanks, Mark