开发者

How to implement multiple selection on Rails 3

开发者 https://www.devze.com 2023-03-29 23:36 出处:网络
I have an index where I\'m showing a list of documents. I would like to implement a multiple select in order to开发者_如何学编程 do different actions to the documents the user has selected

I have an index where I'm showing a list of documents. I would like to implement a multiple select in order to开发者_如何学编程 do different actions to the documents the user has selected

I have created a

<%= check_box_tag 'id', 'document.id %>

for each document, inside a form_tag

But if I select multiple checkboxes, the params that are passed to the action are overwrited and I'm just receiving the id of the last checkbox I've selected in the id param.

¿Anyone knows how to implement multiple select?¿Any other approach? I'm running Rails 3 and Ruby 1.8.7

Thanks in advance


You need to set :multiple => true

<%= check_box_tag 'id', document.id, :multitple => true %>

This will give you results in form of an array in params[:id]


Minor correction (plural):

<%= check_box_tag 'ids[]', document.id %>

ensure your model is properly set for attr_accessible something like :document_ids

0

精彩评论

暂无评论...
验证码 换一张
取 消