0
我在dev和production(在共享的web服务器上)有区别。在我的应用程序控制器我有这两条线的方法的一部分,它存储的更新:current_user未存储在生产服务器上的会话
@activity.update_attribute(:user_id, current_user.id)
@activity.update_attribute(:company_id, current_user.company.id)
在开发中既USER_ID和的company_id是已知的,得到保存在数据库中。这是因为在current_user中存在一个用于存储会话信息的before过滤器。
但是,在共享生产服务器上使用完全相同的代码时,它在将记录存储到数据库时发生错误,而当我查看日志时,这两个值均为NULL。错误是:
"ActiveRecord::StatementInvalid (Mysql2::Error: Column 'company_id' cannot be null: INSERT INTO `activities` (`activity`, `company_id`, `created_at`, `updated_at`, `user_id`) VALUES ('Test', NULL, '2011-12-09 09:01:29', '2011-12-09 09:01:29', NULL)):"
对我来说似乎对生产的会话存放不当。我一直在寻找,唯一能想到的就是这篇文章,它说你必须在用户模型中添加“allow_http_basic_auth”。当我这样做,(我不使用Authlogic的方式),然后返回此错误:
undefined method `allow_http_basic_auth' for #<User:0x007f91990efce0>
任何想法将是巨大的!
编辑:在应用控制器我有这样的:
helper_method :current_user
def current_user
@current_user ||= User.find(session[:user_id]) if session[:user_id]
end
# Save new activity/update
def store_update(activity)
@activity = Activity.new
@activity.update_attribute(:activity, activity)
@activity.update_attribute(:user_id, current_user.id)
@activity.update_attribute(:company_id, current_user.company.id)
@activity.save
end
的错误是从SQL INSERT,不更新,这是正确的地方抛出异常? – bender
SQL INSERT错误是由未使用current_user值设置user_id和company_id引起的。 – John
你可以在过滤器中显示应该设置实例变量的相关部分吗?您还使用哪个会话存储? – edk750