This question seems a little basic, but considering I have 'pages#show' with a show page with url 'history'. How could I add this specific show page to a link:
= link_to 'History', pages_path(@?????)
PD1: I would prefer avoid using
:id since I tend to seed a lot of data, and per
db:seed all id's tend to change.
PD2: I know I can achieve this creating an action and then setting it on router.rb. But in long time that's a great deal of time consumption.
Best How To :
rails generate migration AddPermalinkToPages permalink:string
After you added then you need to create the permalink on the fly when you are saving the page or updating it. I usually do it in the model so I keep the controller clean. You can define it in a PagesHelper if you want user to assign the permalink and call in in the view. It really depends on how you want to interact with user.
Anyway, ( if you want to define it in Model then )
In your page.rb
In your pages_controller.rb ( if you need to) - here id will be the permalink so your user will be something like this /history/a-page-slug
## Use callbacks to share common setup or constraints between actions.
@page = Page.find_by_permalink(params[:id])
Don't need to do anything with your route.
Please let me know if you need more help.