【发布时间】:2011-03-06 04:24:05
【问题描述】:
刚刚遇到类似http://www.ruby-forum.com/topic/216433的问题
我需要从助手访问控制器实例变量。
这是我完成的代码,但它不起作用。
控制器:
class ApplicationController < ActionController::Base
helper_method :set_background_type #for action only background setting
#for controller-wise background setting
def set_background_type(string)
@background_type = string
end
end
助手:
module ApplicationHelper
def background_type
@background_type || 'default'
end
end
布局:
<body class="<%= background_type %>">
【问题讨论】:
标签: ruby-on-rails-3