Jeremy Bray
Jeremy Bray

Reputation: 444

Redirect routes

I have an old wordpress woocommerce site that I rebuilt in rails.

Obviously it has a Product model and Products controller with routes.

The site is ready to launch.

My only problem is the old links go

www.mydomain.com/product/product-name

how do I either redirect or change my

www.mydomain.com/products/product-name

my routes file looks like so

resources :products do
    resource :like, only: [:create,:destroy], module: :products
    resource :collect, only: [:create,:destroy], module: :products do
      put :sort, on: :collection
    end
    member do
      get :toggle_status
    end
  end

Upvotes: 0

Views: 52

Answers (2)

m3characters
m3characters

Reputation: 2290

http://guides.rubyonrails.org/routing.html#redirection

get '/product/:name', to: redirect('/products/%{name}')

Upvotes: 0

widjajayd
widjajayd

Reputation: 6253

you may check rails routing guide check section 4.7 Translated Paths

for your case above the translated route

resources :products, path: 'product'

Upvotes: 1

Related Questions