Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

passing array parameters to path

I need to pass parameters to a path so that the path looks like the following:

http://localhost/submission_app/submissions?search_submission_type=ISH&submission_status_arr[]=51

I tried

submissions_path(:search_submission_type => "ISH", :submission_status_arr[] => 51 )

But am getting wrong number of arguments (0 for 1..2) error message on my view page.

I then tried:

submissions_path("search_submission_type=ISH&submission_status_arr[]=51")

But this one gives me the following url (Note the dot instead of &amp before the argument)

http://localhost/submission_app/submissions.search_submission_type=ISH&submission_status_arr[]=51

How do I need to pass the parameters so that I get the correct format for the url?

Your suggestions are most appreciated. Thank you

like image 319
Kim Avatar asked Aug 28 '26 09:08

Kim


2 Answers

Rails uses parameter[]=value to signify that parameter should be considered an array.

You just need to pass an array to the path helper to get rails to generate the path for you.

submissions_path(:search_submission_type => "ISH", :submission_status_arr => [51] )

like image 89
Tom Harris Avatar answered Aug 30 '26 22:08

Tom Harris


Correct syntax is

submissions_path(:search_submission_type => "ISH", :submission_status_arr => [51] )
like image 45
crackedmind Avatar answered Aug 30 '26 22:08

crackedmind



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!