views:

142

answers:

1

Id like to be able to create checkboxes for a list of objects. Then offer the user a number of actions to perform on the objects selected. I.e. delete, archive etc.

I know of ryan's screencasts but it doesnt explain how to create links to multiple actions for the selected objects. It just showed him create a form_tag with a url to one action and a submit button.

A: 

I think you can do it in two ways.

First: you can add as many buttons to one form as you want:

<%= f.submit "Action 1" %>
<%= f.submit "Action 2" %>
<%= f.submit "Action 3" %>

And all of them are submitted to one action in which you can check:

if params[:commit] == "Action 1"
  do some stuff for action 1
elsif params[:commit] == "Action 2"
  do other stuff
... and so on
end

Another way is to use some js. On example when user clicks on button "Action 2" it changes "action" parameter in form and submits data to this action.

EDIT: In case of translated websites, you can do it like this:

<%= f.submit (I18n.t :action_1) %>

and in controller:

if params[:commit] == I18n.t :action_1
...
end

And in en.yml add:

action_1: Action 1

In pl.yml add:

action_1: Akcja 1

and so on.

klew
it's doens't work if you internationalize your code :(
shingara
In controller you can also compare with translated values so it solves your problem. On the other side, second way of solving this problem, which inludes js is correct for internationalization.
klew