[英]ApplicationController Method with Equal Sign
In Rails 4 I'm trying to do this: 在Rails 4中,我试图这样做:
class ApplicationController < ActionController::Base
# does not work
def x=(value)
session[:x] = value
end
# I have to do this instead
def set_x(value)
session[:x] = value
end
end
When I try to call x = 1
from a child controller, I don't get an error, however the session variable doesn't get set. 当我尝试从子控制器调用
x = 1
,没有收到错误,但是没有设置会话变量。 Running set_x 1
works as expected though. 运行
set_x 1
可以正常工作。
我认为这是范围问题,而不是调用x = 1
,请尝试调用self.x = 1
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.