简体   繁体   English

Rails - 从实例变量(控制器或视图?)设置布局中的标题

[英]Rails - Setting title in layout from instance variable (controller or view?)

Let's say I have something like this in my application layout: 假设我的应用程序布局中有类似的东西:

<title> <%= @page_title | MyPage </title>

I am wondering where is it better to set that instance variable. 我想知道在哪里设置该实例变量更好。 In the controller action, or in the view ? 控制器操作中,还是在视图中 Does it matter at all? 它有关系吗? I am asking in both performance and closest MVC way of doing it. 我要求性能和最接近MVC的方式。

Rails encourages the use content_for in your views to pass this kind of content around. Rails鼓励在您的视图中使用content_for来传递这种内容。 Others may have a better sense of how efficient this approach is, however. 然而,其他人可能更好地了解这种方法的效率。

I'll recomend you to use meta-tags gem . 我建议你使用meta-tags gem You can easily set title set_meta_tags :title => 'Member Login' and other SEO options like meta and etc. 您可以轻松设置标题set_meta_tags :title => 'Member Login'和其他SEO选项,如meta等。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM