Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

This project is archived and is in readonly mode.

Problem with validates_presence_of

#5143

I have found a problem with rails 2.3.8.I have my model user with some attributes (name,email,password).On validating the model using validates_presence_of i found this bug.Validates_presence_of is accepting the non-model attributes, for example my attributes are name,mail and pass.But when i just simply gave a non attribute like validates_presence_of :love.On submitting the form its throwing the error message "Love can't be blank".

So please suggest whether this a bug or not?

Reported by judearasu (at gmail) · July 18th, 2010 @ 05:17 AM

State: invalid
Milestone: none
Assigned to: Yehuda Katz (wycats) Yehuda Katz (wycats)
Importance: Low

Activity

  1. judearasu (at gmail)
    judearasu (at gmail)
    • Tag changed from validates_presence_of to 2.3.8, validates_presence_of

    July 18th, 2010 @ 07:20 PM

  2. judearasu (at gmail)
    judearasu (at gmail)
    • Assigned user set to Yehuda Katz (wycats)
    • Tag changed from 2.3.8, validates_presence_of to 2, validates_presence_of

    July 19th, 2010 @ 06:28 AM

  3. Alex Sharp
    Alex Sharp

    Can you paste in your model or post a link to a gist?

    July 19th, 2010 @ 06:58 AM

  4. judearasu (at gmail)
    judearasu (at gmail)

    http://gist.github.com/481073

    in the file :empid attribute is not available in the model.But its throwing Empid can't be blank?.

    So whether validates_presence_of will accept non-attributes of the model or not?

    July 19th, 2010 @ 07:38 AM

  5. Alex Sharp
    Alex Sharp

    You are validating presence of :empid on line 14:

    validates_presence_of :name,:empid,:email,:password,:username

    I'm not sure I understand the incorrect behavior here.

    July 19th, 2010 @ 08:35 AM

  6. judearasu (at gmail)
    judearasu (at gmail)

    Actually :empid attribute is not available in model.

    My user model is having :name,:email

    so as per the validates_presence_of it should take only the attributes :name and :email.

    But it is accepting the wrong attributes also.

    Whether validates_presence_of will the take model attributes or any word starts with :

    July 19th, 2010 @ 09:25 AM

  7. judearasu (at gmail)
  8. Alex Sharp
    Alex Sharp

    I don't think it's the responsibility of Rails validations to make sure that the validations you've defined map to actual database fields. Your validations are model (behavior) logic, not persistence logic. Moreover, you may indeed want to have validations on model attributes that don't exist in the database. In my opinion, this is the correct behavior, not a bug.

    July 20th, 2010 @ 05:38 AM

  9. Andrea Campi
    Andrea Campi
    • Tag changed from 2, validates_presence_of to 2-3-stable, validates_presence_of

    October 16th, 2010 @ 11:39 PM

  10. Aditya Sanghi
    Aditya Sanghi
    • State changed from new to invalid
    • Importance changed from to Low

    I thought validations on virtual attributes was a feature. Invalidating the ticket. If you feel otherwise please chime in and continue discussion.

    October 17th, 2010 @ 05:47 AM