Rails 应用程序无法识别生产中批量分配的 own_to 关联

发布于 2024-09-25 03:33:46 字数 811 浏览 3 评论 0原文

我有一个属于客户经理的帐户模型:

class Account < ActiveRecord::Base  
  belongs_to :account_manager, :class_name => 'User'
  validates_presence_of :account_manager
end

我的控制器如下所示:

def create
    @account = Account.new(params[:account])
...

请求如下所示:

Started POST "/accounts" for 74.61.248.151 at Sun Sep 26 16:12:26 +0000 2010
  Processing by AccountsController#create as HTML
  Parameters: {"commit"=>"Create Account", "account"=>{"name"=>"", "account_manager_id"=>["171"]}, "authenticity_token"=>"T4ERO0iMtseI952LP/9gf5EcYrRCE/3pQFdSgqi3hNg=", "utf8"=>"\342\234\223"}

由于某种原因,在提交此请求后,表单显示客户经理为空。但这仅发生在生产中,而不发生在本地开发中。有人以前见过这个吗?唯一的区别是我在生产中使用 REE,但我认为这不会成为问题,因为这是 Rails 功能。 Rails 版本在本地和产品上相同 - 3.0.0

I have an Account model that belongs to an account manager:

class Account < ActiveRecord::Base  
  belongs_to :account_manager, :class_name => 'User'
  validates_presence_of :account_manager
end

My controller looks like this:

def create
    @account = Account.new(params[:account])
...

A request looks like this:

Started POST "/accounts" for 74.61.248.151 at Sun Sep 26 16:12:26 +0000 2010
  Processing by AccountsController#create as HTML
  Parameters: {"commit"=>"Create Account", "account"=>{"name"=>"", "account_manager_id"=>["171"]}, "authenticity_token"=>"T4ERO0iMtseI952LP/9gf5EcYrRCE/3pQFdSgqi3hNg=", "utf8"=>"\342\234\223"}

For some reason, after submitting with this request the form says that the account manager is blank. But this only happens on production, not on local dev. Anyone seen this before? The only difference is I use REE on production but I wouldn't think that would be an issue since this is Rails functionality. Rails version is the same on local and prod - 3.0.0

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

2024-10-02 03:33:46

我不得不做这个丑陋的黑客:

@account.account_manager_id = params[:account][:account_manager_id].first.to_i unless params[:account][:account_manager_id].blank?

也许这是一个 Rails 错误。很想看看其他人是否遇到这个问题。

I had to do this ugly hack:

@account.account_manager_id = params[:account][:account_manager_id].first.to_i unless params[:account][:account_manager_id].blank?

Maybe this is a rails bug. Curious to see if other people experience this issue.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文