Hello everyone i am trying to save a nested model but it will always
fail because 2 fields are missing
I tried to examine what happens so i print the object to yaml, here s
what i got:
- &id001 !ruby/object:Contract
  attributes:
    price:
    room_id:
    start_date: 15/09/2009
    created_at:
    is_consecutive: false
    same_sex: false
    comments:
    updated_at:
    has_keys: false
    touched_by:
    amount_to_keep: 0
    house_id:
    user_id: 0
    paid_percent: 0.0
    has_signed: false
    shared: true
    house_rating: 0
    deposit_returned: false
    service_rating: 0
    booking_date:
    end_date: 14/02/2010
    active: false
  attributes_cache:
    start_date:
    end_date:
  changed_attributes: {}
  errors: !ruby/object:ActiveRecord::Errors
    base: *id001
    errors:
      base:
      - !ruby/object:ActiveRecord::Error
        attribute: :base
        base: *id001
        message: Please tell us when your rental period should start
        options: {}
        type: Please tell us when your rental period should start
      - !ruby/object:ActiveRecord::Error
        attribute: :base
        base: *id001
        message: Please tell us when your rental period should end
        options: {}
        type: Please tell us when your rental period should end
  new_record: true
The only fields that i am checking for presence are the start_date and
end_date as you can see in the yaml they have a value but then
validation fails.
Thanx a lot for your time
Could it be that the DB itself ha constraints you''re not thinking of? For example, not nullable fields that are getting a null. Are you using a bang method (save! or create!)? If you''re not, change it at least for testing, it will most likely make the app. raise an error and might be very informative. If you are using your_object.save it will only return true/false and finding out what is wrong is going to be more complicated. Posting some code might also help others to help you. On Sep 20, 11:13 am, PanosJee <panos...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Hello everyone i am trying to save a nested model but it will always > fail because 2 fields are missing > I tried to examine what happens so i print the object to yaml, here s > what i got: > > - &id001 !ruby/object:Contract > attributes: > price: > room_id: > start_date: 15/09/2009 > created_at: > is_consecutive: false > same_sex: false > comments: > updated_at: > has_keys: false > touched_by: > amount_to_keep: 0 > house_id: > user_id: 0 > paid_percent: 0.0 > has_signed: false > shared: true > house_rating: 0 > deposit_returned: false > service_rating: 0 > booking_date: > end_date: 14/02/2010 > active: false > attributes_cache: > start_date: > end_date: > changed_attributes: {} > > errors: !ruby/object:ActiveRecord::Errors > base: *id001 > errors: > base: > - !ruby/object:ActiveRecord::Error > attribute: :base > base: *id001 > message: Please tell us when your rental period should start > options: {} > > type: Please tell us when your rental period should start > - !ruby/object:ActiveRecord::Error > attribute: :base > base: *id001 > message: Please tell us when your rental period should end > options: {} > > type: Please tell us when your rental period should end > new_record: true > > The only fields that i am checking for presence are the start_date and > end_date as you can see in the yaml they have a value but then > validation fails. > > Thanx a lot for your time
I found the errors 2 days ago, it is quite strange. I was saving the dates with this format dd/mm/yy That would work for parent model but not the nested! I had to change the date to yy-mm-dd for the nested object and it just worked! On 23 Σεπτ, 03:44, pepe <P...-1PhG29ZdMB/g+20BJ0uB2w@public.gmane.org> wrote:> Could it be that the DB itself ha constraints you''re not thinking of? > For example, not nullable fields that are getting a null. > > Are you using a bang method (save! or create!)? If you''re not, change > it at least for testing, it will most likely make the app. raise an > error and might be very informative. If you are using your_object.save > it will only return true/false and finding out what is wrong is going > to be more complicated. > > Posting some code might also help others to help you. > > On Sep 20, 11:13 am, PanosJee <panos...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > Hello everyone i am trying to save a nested model but it will always > > fail because 2 fields are missing > > I tried to examine what happens so i print the object to yaml, here s > > what i got: > > > - &id001 !ruby/object:Contract > > attributes: > > price: > > room_id: > > start_date: 15/09/2009 > > created_at: > > is_consecutive: false > > same_sex: false > > comments: > > updated_at: > > has_keys: false > > touched_by: > > amount_to_keep: 0 > > house_id: > > user_id: 0 > > paid_percent: 0.0 > > has_signed: false > > shared: true > > house_rating: 0 > > deposit_returned: false > > service_rating: 0 > > booking_date: > > end_date: 14/02/2010 > > active: false > > attributes_cache: > > start_date: > > end_date: > > changed_attributes: {} > > > errors: !ruby/object:ActiveRecord::Errors > > base: *id001 > > errors: > > base: > > - !ruby/object:ActiveRecord::Error > > attribute: :base > > base: *id001 > > message: Please tell us when your rental period should start > > options: {} > > > type: Please tell us when your rental period should start > > - !ruby/object:ActiveRecord::Error > > attribute: :base > > base: *id001 > > message: Please tell us when your rental period should end > > options: {} > > > type: Please tell us when your rental period should end > > new_record: true > > > The only fields that i am checking for presence are the start_date and > > end_date as you can see in the yaml they have a value but then > > validation fails. > > > Thanx a lot for your time