Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails 4 - Passing Params via link_to?

I have a single form - depending which link the user clicks to display the form, I want different hidden params to be passed to the record and saved upon submission. Is there a nice way to do this? Thanks in advance!

For instance:

<%= link_to 'General Request', new_request_path %>

<%= link_to 'Project Request', new_request_path %> ### -> set request.project = true

<%= link_to 'Administrative Request', new_request_path %>  ### -> set request.admin = true
like image 279
Katie M Avatar asked Jul 17 '13 17:07

Katie M


1 Answers

For your examples, you'd use:

<%= link_to 'Project Request', new_request_path(project: true) %>

which would produce a link like http://127.0.0.1:3000/request?project=true

and

<%= link_to 'Administrative Request', new_request_path(admin: true) %>

which would produce a link like http://127.0.0.1:3000/request?admin=true

like image 149
James Chevalier Avatar answered Sep 21 '22 20:09

James Chevalier