Question

I am trying to create a scaffold called 'Pages'.

So far everything is fine but the page structure now needs to change where it currently is:

http://0.0.0.0:3000/pages/the-page-name

What I need to do now is have this instead:

http://0.0.0.0:3000/the-page-name

In my routes.rb I have this:

resources :pages

This obviously maps all routes within the model to this base but I want to hide this.

Is it entirely possible?

Thanks,

Was it helpful?

Solution

Taken from the Rails Routing Guide, you could do this:

get '*pages', to: 'pages#show', format: false

I would recommend you make it the very last route you have, since the Rails router matches the request with the first route, and having a wildcard early in your routes file will end up clobbering all your other routes/resources.

OTHER TIPS

You can specify a path

resources :pages, path: ''
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top