Rails app does not recognize mass assigned belongs_to association in production
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 differe开发者_高级运维nce 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
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.
精彩评论