title: Using data from associated model in form, Rails 3
body: <p>There are a lot of similar topics, but it doesn't help me.
  There is a Account model</p>
  
  <pre><code>class Account &lt; ActiveRecord::Base
    belongs_to :user
    belongs_to :currency
  
    attr_accessible :currency
    accepts_nested_attributes_for :currency
  end
  </code></pre>
  
  <p>I added attr_accessible and accepts_nested_attributes_for , but actually i don't know they needed or not. Another model Currency that that has 3 items - USD, EUR, RUR</p>
  
  <pre><code>class Currency &lt; ActiveRecord::Base
    has_many :accounts
    attr_accessible :id
  
    accepts_nested_attributes_for :accounts
  end
  </code></pre>
  
  <p>So in account form I have a selectbox with currency:</p>
  
  <pre><code>&lt;%= form_for @account do |f| %&gt;
  
    &lt;div class="field"&gt;
  &lt;%= f.label :name %&gt;&lt;br /&gt;
  &lt;%= f.text_field :name %&gt;
    &lt;/div&gt;
  
    &lt;div class="field"&gt;
  &lt;%= f.label :currency %&gt;&lt;br /&gt;
  &lt;%= select_tag(:currency, options_from_collection_for_select(Currency.all, :id, :name),\
        :id =&gt; "account_currency_id", :name =&gt; "account[currency][id]", :prompt =&gt; "Выберите валюту...")%&gt;
    &lt;/div&gt;
  
  &lt;div class="actions"&gt;
  &lt;%= f.submit "Сохранить" %&gt;
    &lt;/div&gt;
  
  &lt;% end %&gt;
  </code></pre>
  
  <p>And when i'm trying to crate Account error occurred:</p>
  
  <pre><code> ActiveRecord::AssociationTypeMismatch in AccountsController#create
   Currency(#52889580) expected, got ActiveSupport::HashWithIndifferentAccess(#28841960)
  </code></pre>
  
  <p>Request parameters:</p>
  
  <pre><code>{"utf8"=&gt;"✓",
    "authenticity_token"=&gt;"VfCshuGyldoI5Q5DThT/RDpwewCh91apgsnmxyppWqI=",
    "account"=&gt;{"name"=&gt;"Основной наличный счет",
    "currency"=&gt;{"id"=&gt;"3"}},
    "commit"=&gt;"Save"}
  </code></pre>
  
  <p>If I try to find Currency from Id manually:</p>
  
  <pre><code>param = params[:account]
  param[:currency] = Currency.find(param[:currency][:id])
  @account = Account.new(param)
  </code></pre>
  
  <p>There are a new error by witch Name doesn't exists. And I don't like that i should manually set <code>:id =&gt; "account_currency_id", :name =&gt; "account[currency][id]"</code> because by default they both "currency".
  Rails 3.1</p>