heroxav
heroxav

Reputation: 1467

Rails: how to use redirect_to properly

I have the following routes defined in my routes file:

constraints( subdomain: "abc" ) do
    get "/action" => "abc#init"
    get "/action/:d" => "abc#action"
end

I assumed that I can redirect from the init action that way:

redirect_to action_path(d: "12345")

But that way the server infinitely redirects to the init action resulting in an browser error.

How can I perform that redircet using tha Rails path helpers?

Upvotes: 1

Views: 188

Answers (1)

Eyeslandic
Eyeslandic

Reputation: 14900

You need to name your routes

constraints( subdomain: "abc" ) do
  get "/action" => "abc#init", as: :init_action
  get "/action/:d" => "abc#action", as: :d_action # something fancier maybe
end

redirect_to d_action_path(d: 'something')

Upvotes: 2

Related Questions