This project is archived and is in readonly mode.
Problem with validates_presence_of
Reported by judearasu (at gmail) | July 18th, 2010 @ 05:17 AM
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?
Comments and changes to this ticket
-
judearasu (at gmail) July 18th, 2010 @ 07:20 PM
- Tag changed from validates_presence_of to 2.3.8, validates_presence_of
-
judearasu (at gmail) July 19th, 2010 @ 06:28 AM
- Assigned user set to Yehuda Katz (wycats)
- Tag changed from 2.3.8, validates_presence_of to 2, validates_presence_of
-
judearasu (at gmail) July 19th, 2010 @ 07:38 AM
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?
-
Alex Sharp July 19th, 2010 @ 08:35 AM
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.
-
judearasu (at gmail) July 19th, 2010 @ 09:25 AM
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 :
-
judearasu (at gmail) July 20th, 2010 @ 04:55 AM
- no changes were found...
-
Alex Sharp July 20th, 2010 @ 05:38 AM
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.
-
Andrea Campi October 16th, 2010 @ 11:39 PM
- Tag changed from 2, validates_presence_of to 2-3-stable, validates_presence_of
-
Aditya Sanghi October 17th, 2010 @ 05:47 AM
- 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.
Create your profile
Help contribute to this project by taking a few moments to create your personal profile. Create your profile »
<h2 style="font-size: 14px">Tickets have moved to Github</h2>
The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>