I am currently developing a blogging system with Ruby on Rails and want the user to define his “permalinks” for static pages or blog posts, meaning:
the user should be able to set the page name, eg. “test-article” (that should be available via /posts/test-article) – how would I realize this in the rails applications and the routing file?
Modifying the
to_parammethod in the Model indeed is required/convenient, like the others said already:But in order to find the posts you also need to change the Controller, since the default
Post.findmethods searches for ID and not pagename. For the show action you’d need something like this:Same goes for the other action methods.
You routing rules can stay the same as for regular routes with an ID number.