PudparK
PudparK

Reputation: 111

Rails: Remove Controller from URL

I've read a couple of posts, but I haven't found a clear solution.

I want to remove the controller from the URL. I'm getting this:

localhost:3000/pages/services

But I want this:

localhost:3000/services

This is my routes file right now:

Rails.application.routes.draw do

  root 'pages#index'

  get 'pages/services'

  get 'pages/specials'

  get 'pages/events'

  get 'pages/about'

end

I suspect that I need to do something here, but I haven't been able to find a decent tutorial. Any suggestions?

Upvotes: 0

Views: 747

Answers (2)

孙悟空
孙悟空

Reputation: 1285

Try this:

match 'services' => "pages#services", :as => :services

You can specify a name for any route using the :as option.

See here

Upvotes: 5

user6615598
user6615598

Reputation: 1

I would just replace it with this:

Rails.application.routes.draw do
  root '#index'
end

Upvotes: -1

Related Questions