0

I have a multiselect dropdown that results in a redirect to URLs that include params like this:

period_id%5B%5D=14&period_id%5B%5D=15

In some circumstances, I need to set these params in my controller. I've tried

params[:period_id[]] = ['25']

and

params['period_id[]'] = ['25']

but this doesn't work.

What's the proper way to do this?

2
  • You want your controller to behave as if those params were passed to you or you're constructing a hash of params to pass to link_to (or similar) ? Commented Aug 11, 2014 at 18:08
  • I want the controller to behave as if those params were passed to it. Commented Aug 11, 2014 at 19:08

1 Answer 1

1

params is a standard ruby Hash so anything can be set as value.

try: params[:period_id] = [14,15,16...]

Sign up to request clarification or add additional context in comments.

2 Comments

This doesn't work for me; when I read the params into an array, using params[:period_id].collect { |s| s.to_i }, they aren't returned in the same way as they are when they are supplied in the URL above.
Didn't understand you. Btw. there is shortcut for your .collect {|s| s.to_i} call. Do it this way: params[:period_id].collect(&:to_i)

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.