Here''s the issue: When I submit a form for updating, @person.update_attributes doesn''t work. But the next nested clause for updating images DOES work. How is that possible? However no matter what I do the Person object will not change its attributes. def edit @person = Person.find(params[:id]) if request.post? @person.update_attributes(params[:person]) #image saving stuff unless params[:image][:data].blank? if @person.image @image = @person.image @image.data = params[:image][:data] @image.save else @image = Image.create(:data => params[:image][:data]) @image.illustratable = @person @image.save end end flash[:notice] = ''Info successfully updated.'' redirect_to :action => ''show'', :id => @person end end ---Development.log--- Processing PeopleController#edit [POST] Session ID: fa1b778f9ca22e894140b08372310404 Parameters: {"commit"=>"Edit", "action"=>"edit", "id"=>"2", "controller"=>"people", "image"=>{"data"=>#<StringIO:0x4c22474>}, "person"=>{"occupation"=>"", "schools"=>"", "religious_preference"=>"Agnosticism", "dislikes"=>"", "birthdate(1i)"=>"1988", "gender"=>"male", "birthdate(2i)"=>"12", "is_smoker"=>"0", "birthdate(3i)"=>"13", "first_name"=>"Test", "homepage_url"=>"", "languages"=>"--- ", "last_name"=>"User Three", "likes"=>"", "nationality"=>"", "hometown"=>"", "email"=>"testuser3-mSy8YtThJsM@public.gmane.org"}} [4;36;1mPerson Load (0.016000) [0;1mSELECT * FROM people WHERE (people.id = ''2'') LIMIT 1 [4;35;1mPerson Columns (0.000000) SHOW FIELDS FROM people [4;36;1mSQL (0.000000) [0;1mBEGIN [4;35;1mPerson Load (0.000000) SELECT * FROM people WHERE (people.email = ''testuser3-mSy8YtThJsM@public.gmane.org'' AND people.id <> 2) LIMIT 1 [4;36;1mSQL (0.000000) [0;1mCOMMIT [4;35;1mImage Columns (0.000000) SHOW FIELDS FROM images [4;36;1mImage Load (0.016000) [0;1mSELECT * FROM images WHERE (images.illustratable_id = 2 AND images.illustratable_type = ''Person'') LIMIT 1 [4;35;1mSQL (0.000000) BEGIN [4;36;1mSQL (0.000000) [0;1mCOMMIT -- 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 -~----------~----~----~----~------~----~------~--~---
On 12/15/06, Taylor Strait <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > Here''s the issue: When I submit a form for updating, > @person.update_attributes doesn''t work. But the next nested clause for > updating images DOES work. How is that possible? However no matter > what I do the Person object will not change its attributes.My first guess is that a validation is failing. What does the update_attributes call return? --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Good call on the validations being the cause. These two validations were causing the update to silently fail: validates_inclusion_of :so, :in => SEXUAL_ORIENTATIONS, :allow_nil => true validates_inclusion_of :rp, :in => RELIGIONS, :allow_nil => true However, these required validations pass: validates_inclusion_of :gender, :in => GENDERS validates_inclusion_of :role, :in => ROLES And yes I have put "require constants" in my People.rb. Does anyone have any ideas as to why my :allow_nil validations are failing? :allow_nil DOES work doesn''t it? -- 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 -~----------~----~----~----~------~----~------~--~---
Taylor Strait wrote:> Good call on the validations being the cause. These two validations > were causing the update to silently fail: > > validates_inclusion_of :so, :in => SEXUAL_ORIENTATIONS, :allow_nil => > true > validates_inclusion_of :rp, :in => RELIGIONS, :allow_nil => true > > However, these required validations pass: > > validates_inclusion_of :gender, :in => GENDERS > validates_inclusion_of :role, :in => ROLES > > And yes I have put "require constants" in my People.rb. Does anyone > have any ideas as to why my :allow_nil validations are failing? > :allow_nil DOES work doesn''t it?you might want to add a conditional around update_attributes to catch the validation: if request.post? if @person.update_attributes(params[:person]) #image saving stuff unless params[:image][:data].blank? if @person.image @image = @person.image @image.data = params[:image][:data] @image.save else @image = Image.create(:data => params[:image][:data]) @image.illustratable = @person @image.save end end flash[:notice] = ''Info successfully updated.'' redirect_to :action => ''show'', :id => @person else render :action => "edit" end end make sure you have <%= error_messages_for :person %> in your edit view --jake -- 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 -~----------~----~----~----~------~----~------~--~---
On 12/16/06, Taylor Strait <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > Good call on the validations being the cause. These two validations > were causing the update to silently fail: > > validates_inclusion_of :so, :in => SEXUAL_ORIENTATIONS, :allow_nil => > true > validates_inclusion_of :rp, :in => RELIGIONS, :allow_nil => true > > However, these required validations pass: > > validates_inclusion_of :gender, :in => GENDERS > validates_inclusion_of :role, :in => ROLES > > And yes I have put "require constants" in my People.rb. Does anyone > have any ideas as to why my :allow_nil validations are failing? > :allow_nil DOES work doesn''t it?My guess here would be that the values are '''' (empty string), and not nil. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---