0

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_message_ids(CODE TO RETRIEVE CHECKBOX ARRAY GOES HERE)

Any suggestions?

2 Answers 2

2

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
Sign up to request clarification or add additional context in comments.

4 Comments

@Jonah My name isn't "meager", also: @dispatches = Dispatch.find_by_message_ids(params[:message_ids]) if params[:message_ids]
Sorry about that! And i actually got it to work by adding an unless params[:message_ids].blank? but thanks for your help!
@Jonah I normally hate when people do this, but: Upvotes are the accepted way of saying "thanks".
Ofcourse! I went to accept before but it "accept in 9 minutes" Thanks for the reminder!
1

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.