Johnny Cash
Johnny Cash

Reputation: 5147

rails 301 redirect for resources with path option

I have routes like this

resources :people, :path => "designers", :only => [:index, :show] do
  member do
    post 'add_favorite_designer'
    post 'remove_favorite_designer'
  end
end

I can use both of example.com/people and example.com/designers.However I want to example.com/people redirect with 301 code to example.com/designers and I want to implement it for all resources with path option.Is there any way to automate it ?

Upvotes: 1

Views: 129

Answers (1)

Baldrick
Baldrick

Reputation: 24340

The path /people should not be available anymore because it's been replaced by /designers when you use the :path parameters.

If you want to redirect all requests from /people to /designers, use

match '/people/*action', to: redirect {|p, req| "/designers/#{p[:action]}" }

Upvotes: 1

Related Questions