0

There are several questions, which explain how to pass request parameters to a redirect (this and this). However, I don't see from their answers how to insert new parameters that weren's in the request already.

I want to do something like:

get '/models', to: redirect('/models?foo=bar&baz=qux')

When I do this, I get:

Redirected to http://localhost:3000/models
Completed 302 Found in 2704ms (ActiveRecord: 140.6ms)


Started GET "/models" for 127.0.0.1 at 2014-11-18 16:51:31 +0200


Started GET "/models?foo=bar&baz=qux" for 127.0.0.1 at 2014-11-18 16:51:31 +0200


Started GET "/models?foo=bar&baz=qux" for 127.0.0.1 at 2014-11-18 16:51:31 +0200


Started GET "/models?foo=bar&baz=qux" for 127.0.0.1 at 2014-11-18 16:51:31 +0200


Started GET "/models?foo=bar&baz=qux" for 127.0.0.1 at 2014-11-18 16:51:31 +0200

and eventually This page has a redirect loop.

Probably I shouldn't do this in the routes.rb, but assign default values of the index action in the controller, but the thing is I want my page to have ?foo=bar&baz=qux appended to the URL. How can I do this?

Community
  • 1
  • 1
Alexander Popov
  • 23,073
  • 19
  • 91
  • 130
  • Why would you want this? Can't you just specify in your controller that if those params aren't there do whatever? – j-dexx Nov 18 '14 at 15:05
  • The thing is I am highlighting certain tabs in the navigation based on the location of the page, using `current_page?` method. The highlighting depends on query parameters/instance variables. Basically all my links in the code contain the write parameters, but I want to hedge against the case, when the user manually deletes the parameters in the url and just enters `/models`. – Alexander Popov Nov 18 '14 at 16:58

0 Answers0