开发者

Change title based on presence of params

开发者 https://www.devze.com 2023-03-18 18:00 出处:网络
I currently have a project for data storage record开发者_运维问答s. There is a nested resource, disks -> works.

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}
0

精彩评论

暂无评论...
验证码 换一张
取 消