In Rails 4 I'm trying to do this:
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. Running set_x 1
works as expected though.
我认为这是范围问题,而不是调用x = 1
,请尝试调用self.x = 1
。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.