Wolfgang Klinger wrote:> *hiya!*
>
> I have a form field with:
> --------
> <%= datetime_select :ownership, :bought_on, { :include_blank => true
}
> %>
> --------
> and in the controller:
> --------
> # ownership has owner_id, house_id, bought_on (datetime)
> ownership = Ownership.new(:owner => @owner, :house => House.find
> (params[:house][:id]))
> ownership.update_attributes(params[:ownership])
> --------
> because the "bought_on" parameter is not a single value:
> "ownership"=>{"bought_on(2i)"=>"4",
"bought_on(3i)"=>"4",
> "bought_on(4i)"=>"04",
"bought_on(5i)"=>"12",
"bought_on(1i)"=>"2003"}
>
> How can I pass that to "new" as my solution results in
> two sql statements (insert and an unnecessary update).
Firstly, Ownership.create!(hash) is more efficient and less code.
To get the hash you need, how about
hash = {:owner_id => @owner.id, :house_id =>
params[:house][:id]}.merge!(params[:ownership]).
This two part solution makes debugging easier as you can inspect hash
before it goes into create!()
Cheers,
magpie
--
Posted via http://www.ruby-forum.com/.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---