Gurmukh Singh Gurmukh Singh - 4 months ago 8
Ruby Question

Change model name in browser rails

I have a model in rails and I called it

free_mess


And my routes file contain
resources :free_mess


Obviously this model name is not ideal to show in the browser, it shows up like this:

localhost:3000/free_mess/show
localhost:3000/free_mess/index
localhost:3000/free_mess/message1


I need to change the
free_mess
in the browser to something more readable like
'messages'
. So that the browser shows this:

localhost:3000/messages/show
localhost:3000/messages/index
localhost:3000/messages/message1

Answer
resources :free_mess, path: 'messages'

This will add alias routes in your app.

But if you want to rename the path AND the shhelper methods, then you should do:

resources :stories, :path => :books, :as => :books

See: Overriding the Named Helpers