Reputation: 1
I have a website with a controller named "Posts".
I would like to redirect "example.com/posts" to "example.com" as they display the same information.
I know this is done in the routes.rb file but after a few hours of searching I don't think I'll figure it out. Any help is appreciated, thanks!
I am using Rails 4.0 on Ruby 2.0
Upvotes: 0
Views: 748
Reputation: 878
In your routes.rb
file make sure the root :to
is at the top of your code. Then you would need to assign a redirect for the GET request you want to always sent there:
root :to => 'posts#index'
get '/posts', to: redirect('/')
Upvotes: 0
Reputation: 180
You can read all about redirection in routes, here: http://guides.rubyonrails.org/routing.html#redirection
get '/posts', to: redirect('/')
...
root to: 'posts#index'
Upvotes: 2