开发者

Pass values of checkboxes into an array?

Im trying to update someone else's Rails app. Right now, an HTML table displays values from a database. What i want is to be able to display a checkbox for each row and on submit, the values of the checkboxes are sent into an array (and the values shouldnt be "checked" or "unchecked", they should be the id's of the database row).

Heres what i have so far.

Checkbox : (message.id being a dynamic id)

 <%= check_box_tag "message_ids[]", message.id %>

And on the controller:

 @dispatches = Dispatch.find_by开发者_如何学JAVA_message_ids(CODE TO RETRIEVE CHECKBOX ARRAY GOES HERE)

Any suggestions?


Have you tried inspecting the value of params?

Chances are this will work:

@dispatches = Dispatch.find_by_message_ids(params[:message_ids])

But if it doesn't, just look at what is being sent to your page. Try one of these:

logger.info(params)

or

raise (params.inspect)

or

render :inline => params.to_yaml


Check what you receive in your params because they're probably there if this is defined correctly. The current parameters are always logged in log/development.log which is something you should have open any time you're debugging something.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜