Ruby on Rails Breadcrumbs dynamic link title content
How do i dynamically link the video name to the title content of my breadcrumbs.
I've followed the tutorial in https://github.com/sekrett/crumble
/config/initializers/breadcr开发者_Python百科umbs.rb
crumb :root, "Home", :root_path
crumb :video, {:videos => :name}, :video_path
trail :videos, :show, [:root, :video]
In my video show page, the breadcrumb is as shown:
"Home >> translation missing: en.breadcrumbs.video"
How do i access the title of the video and display it dynamically?
In order to use `crumb :video, {:videos => :name}, :video_path`, you should firstly define a new breadcrumbs node in your `.yml` file, then make sure that the object `@videos` exists in your context, and the object `@videos` has a valid method "name" (which will return a string)
In the code you provided, you use `video_path`, so I guess you are using "show" method for the model Video (in CRUD), so you can check the controller for Video model again to make the correct translation.
Anyway, because the value `params[:id]` is available in the context of the "show" method. You can make use of it and simply change your code to something like below:
crumb :video, '#{Video.find(params[:id]).name}', :video_path, :params => :id
This way may be "not pretty" (as mentioned in the link you provided), but you can achieve what you want without define a new breadcrumbs node in a new `.yml` file
精彩评论