Ruby on Rails
Friday, November 30, 2012
[SOLVED] in my functional test I had a bad :put ,
assert_difference [ 'Place.count', 'Geolocation.count' ], 0 do
put :update, :id => @place[:id],
:geolocation_attributes => {
street_address: @street_address,
postal_code: @postal_code,
city: @city,
country: @country }
end
when I should have added the :place => { :geolocation_attributes => { !!
assert_difference [ 'Place.count', 'Geolocation.count' ], 0 do
put :update, :id => @place[:id], :place => {
:geolocation_attributes => {
street_address: @street_address,
postal_code: @postal_code,
city: @city,
country: @country }
}
end
updating correctly now
Le vendredi 30 novembre 2012 19:01:51 UTC+1, Erwin a écrit :
I have a nested model Place => Geolocationclass Place < ActiveRecord::Basehas_one :geolocation, :dependent => :destroyaccepts_nested_attributes_for :geolocation, :reject_if => :all_blank, :allow_destroy => trueattr_accessible :geolocation_attributesclass Geolocation < ActiveRecord::Basebelongs_to :place----------------------Creating Place + Geolocation is ok ,= simple_form_for @place, :url => backoffice_places_path, :html => {:class => 'form-vertical' } do |f|...= f.simple_fields_for :geolocation do |g|= render "geolocation_fields", :f => gEditing Place + geolocation doesnt pass , the update method receives the new geolocation attributes from the form, but the geolocation instance is not updated... ( no validation error )= simple_form_for @place, :url => backoffice_place_path, :html => {:method => :put, :class => 'form-vertical' } do |f|...= f.simple_fields_for :geolocation_attributes, @place.geolocation do |g|= render "geolocation_fields", :f => gPlace controllerdef edit@place = Place .find(params[:id])def updatedebuggerif @place.update_attributes(params[:place]) debuggerredirect_to backoffice_place_path(@place), notice: t(:place_updated)params{"id"=>"76", "geolocation_attributes"=>{"street_address"=>"19 Camp Road", "postal_code"=>"Greater London SW19 4UW", "city"=>"London", "country"=>"United Kingdom"}, "controller"=>"backoffice/ places", "action"=>"update"} any ide where I am wrong ? thanks for any clue
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@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-talk/-/9B3-GbsASNgJ.
For more options, visit https://groups.google.com/groups/opt_out.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment