![](/img/trans.png)
[英]Add active class to all relative actions inside controller Ruby on Rails
[英]Rails :An attribute seen inside all the actions of a controller
我如何在控制器類中創建一個屬性,該屬性可以在與此控制器相關的所有動作和所有視圖中看到? 謝謝
在Controller中創建一個instance variable
,並確保為該變量提供attr_accessor
,以便所有視圖都可以訪問它。
在控制器中創建之前過濾器
例如:
before_filter:示例
def示例
@variable =真
結束
現在@variable在每個動作和視圖中都可以訪問
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.