The Whiz of Oz
The Whiz of Oz

Reputation: 7043

Unable to pull :page params from the URL on 301 router redirect

I am trying to do a 301 redirect in my router from

/category?page=2

to

/category/page/2

here is my code

get "#{route}(:page)" => redirect {|params,request| "#{params[:name]}/#{route}/page/#{params[:page]" }

It almost works except that the last params[:page] translates to nil. So I get

/category/page/

Tried :page and (:page) - these do not work Appreciate any help.

Upvotes: 0

Views: 47

Answers (1)

alexwbuschle
alexwbuschle

Reputation: 56

This works like you want on rails 4.2.4

get :category, to: redirect { |params, request| "/category/#{request.params[:page]}/"}

If you need to pass the query parameters just add request.params.to_query at the end ;)

Upvotes: 1

Related Questions