0

I'm having trouble passing a param through a link_to in Rails using the below code:

<%= link_to new_registration_path, {:workshop => @workshop.id } do %>

When I pry into the controller, the :workshop is not being included in the params (only controller and action).

Is this a strong params issue?

Jackson Cunningham
  • 4,973
  • 3
  • 30
  • 80
  • 1
    possible duplicate of [Add querystring parameters to link\_to](http://stackoverflow.com/questions/2695538/add-querystring-parameters-to-link-to) – eirikir Aug 11 '15 at 23:48

1 Answers1

1

The workshop param has to be passed to the new_registration_path helper instead of passing it to link_to, like this:

<%= link_to new_registration_path(workshop: @workshop.id) do %>

If you want the URL to be like /something/123 instead of /something?workshop=123, you can change how your route is defined on routes.rb:

get something/:workshop

and then you can pass workshop: 123 to the URL helper.

Oscar Mederos
  • 29,016
  • 22
  • 84
  • 124
  • Ah okay. I was hoping there was a way to do it without a query string – Jackson Cunningham Aug 12 '15 at 00:14
  • If you didn't want to use a query string you could do <%= link_to "/some-registration-path/#{@workshop.id}" do %> Given that in your config/routes.rb you have something like get "some-registration-path/:workshop_id", to: some_controller#some_method – MilesStanfield Aug 12 '15 at 03:53