I currently have a project for data storage record开发者_运维问答s.
There is a nested resource, disks -> works.
I can then filter works index based the presence of params[:disk_id].
The h1 to the page is always "Works". I want it to change to "Works in Disk x", if there is a params[:disk_id] present.
Haven't managed to get a simple DRY way to manage this. Any tips?
You can use content_for construction in your layout to fill the title based on content (HAML syntax in example):
%title
- unless content_for?(:title)
Works
- else
= yield :title
And in your views you can define content_for :title
as you wish:
- content_for :title do
Works if Disk #{@disk.name}
精彩评论