Gemfile 已添加 gem‘request_store'
rails_app 使用自身 webrick 时 正常运行
使用 nginx +passenger 部署 提示错误:
App 27555 stderr: NameError (uninitialized constant User::RequestStore):
App 27555 stderr: app/models/user.rb:32:in current='
App 27555 stderr: app/controllers/application_controller.rb:31:in
setup_user'
———————————————————————————————————————————————————————————————————————————————— 自我尝试过程 内容:设置 rails_env development ; 结果:上述问题未出现,个人初步判断 应该和环境参数有关(未验证到结果) 出现问题:css 加载出现问题,报错如下:
Permission denied @ utime_internal - /opt/growth_pro/tmp/cache/assets/development/sprockets/v3.0/3JbzwSomWffHrDyWaBOTzNRL9G3u81qCSFFDYQQmYs8.cache
————————————————————————————————————————————————————————————————————————————————
user model
class User < ActiveRecord::Base
def self.current=(user)
RequestStore.store[:current_user] = user
end
def self.current
RequestStore.store[:current_user] ||= User.anonymous
end
end
#........................................
application_controller
class ApplicationController < ActionController::Base
before_filter :setup_user
def setup_user
User.current = find_current_user
end
def find_current_user
user =nil
if session[:user_id]
user = User.find(session[:user_id])
else
user= User.anonymous
end
user
end
end