views:

22

answers:

1

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

A: 

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.

Tony
Do you have any `attr_accessible` in you `Account`?
glebm
No. I would have had a warning in the log if that were an issue
Tony
Why `.first` is here? Isn't that `Account belongs to one AccountManager`? If so, why is it not `params[:account][:account_manager_id].to_i`?
PeterWong
Post your view code. Looking at your params it looks like 'account_manager_id' is coming in as an array, which doesn't seem to be want you want. How are you configuring that param in the view?
avaynshtok
Ah that was it. Such a stupid mistake. I used a collection select but set the name to account[account_manager][]. Kinda weird that it worked on dev and not production. Threw me off a bit
Tony