Displaying 20 results from an estimated 6000 matches similar to: "if condition on validates_presence_of is not working"
2007 Oct 17
3
validates_presence_of validating twice?
I''m getting some weird behavior in one of my models. I have a model
defined something like this
class User < ActiveRecord::Base
attr_accessor :password
validates_presence_of :password
end
If I validate the model without specifying a password, I get ["can''t be
blank", "can''t be blank"] for :password instead of just one "cant''t
2006 Oct 26
0
Recipes authentication & validates_presence_of
I''ve implemented Rails Recipe #31, Authentication, and I found that
validating password and password_confirmation just doesn’t work while
the method ‘password=(pass)’ is in the mix, but I need that for the
salt/hashing, no?
If I don’t use validations, the password gets hashed, salted and stored
in the database fine. I can login with same username/password.
However, if I want to
2006 Aug 09
6
How to change the error message easy way
validates_presence_of :fname
results in the error message
"Fname can''t be blank".
What I want is "First Name can''t be blank".
I could do this
def validate
errors.add_to_base("First Name can''t be blank") if fname.blank?
end
I find this clunky and I have to put everyrhing in the validate method. Is
there an easy to get what I want.
I
2005 Oct 14
1
Diff between attr_accessible and attr_accessor
I''m going though the paper back edition of agile development with Rails. On
page #128 I encountered following lines of code:
attr_accessor :password
attr_accessible :name,:password
What''s the difference between attr_accessor and attr_accessible?
-=- Neeraj
_______________________________________________
Rails mailing list
2006 Apr 13
0
Model with file uploads
I''m working on a model for a videos table that include the video info
(title, description) and a couple of uploads (video file, thumb image)
I was going to use the file_column plugin but I dont like the idea of
storing the file names in the database when I dont need to, plus I dont
think it is very flexible.
Here''s what I done. What do you think of this? Any suggestions?
2008 Jul 06
1
ActionView::Base.field_error_proc not getting an error field
In my User form I have standard field to get user record attributes
(first_name, last_name and email)
I also have a select drop_down to choose a role from an array
first_name, last_name and email are user record attributes, but I
defined the role name as a virtual attribute
validates_presence_of :email, :last_name
attr_accessor :role_name
validates_presence_of :role_name, :if
=>
2006 May 18
1
Introspection of validates_presence_of
Hello all.
I don''t know how to get all symbols passed to method
validates_presence_of in model. I''ve trying to use following solution:
class News < ActiveRecord::Base
validates_presence_of :title, :text
def validates_presence_of(*attr_names)
@@obligatory_fields = attr_names
ActiveRecord::Base.validates_presence_of(*attr_names)
end
def obligatory_fields
2006 May 22
2
Weirdness with validates_presence_of
Hi,
I have a call to validates_presence_of in my model and it is behaving very
strangely
my first stab when this happened during testing was
validates_presence_of :impact, :ease_to_implement if Proc.new { |record|
!record.cost_estimate.nil? }
I have three values in my model that I care about with this one. Basically
what I''m trying to get to happen is
if one is there they all must be
2007 Jan 20
1
Not appear error message
I have a partial form "empresa". In new.rhtml of "empresa", I call the
partial form of "usuario". Well, it is happening the following: When
save empresa, and stop in validates, as much in "empresa" how much
"usuario", appear only error message of "empresa", and not of "usuario".
Because this happening?
ps1.: I use flash_message
2006 Apr 12
0
How to get validates_presence_of worked in this situation?
Suppose:
class articles < ActiveRecord::Base
has_many :assistarticles
validates_presence_of :body
end
class assistarticles < ActiveRecord::Base
belongs_to :article
validates_presence_of :detail
end
In the submit form:
<%= text_field ''article'', ''body'' %>
<%= text_field ''assistarticle'', ''detail''
2006 Mar 25
3
validates_presence_of validation order?
I have a form with 3 fields: user_id, email and password.
All 3 fields are required, so I have a "validates_presence_of :user_id,
:email, :password" in my model.
Works, but the validation errors show up in a different order than I
specificed in the validates_presence_of statement.
Is there a way to specify the order in which the validations (and
corresponding error messages) should
2006 Feb 21
1
Custom forms and fieldWithErrors tags
Hi,
(probably) A newbie questions:
I have a form where a user can choose an email address, but there are only
some choices for the domain, so I wrote a helper where the local part of the
email is a text field and the domains is a dropdown list, like:
Select Email: [ my_name ] @ <domain.com>
..which I defined as a helper:
def email_form(tagname, domain_list)
2006 Mar 13
4
undefined method `validates_presence_of'' for #<ProductsContr
Hi,
I am trying to use method `validates_presence_of'' for validating my
input fields on form . I m using it in my action class as follows:-
=======================
validates_presence_of(params[:product][:quantity])
======================
But when I am running my application i m getting error like:-
=========================
undefined method `validates_presence_of'' for
2007 Oct 17
16
rspec causing validates_presence_of to validate twice?
I had posted this on the regular Rails list, but upon trying this in
script/console, it seems like the behavior only exists when running rspec.
I''m getting some weird behavior in one of my models. I have a model
defined something like this
class User < ActiveRecord::Base
attr_accessor :password
validates_presence_of :password
end
If I validate the model without specifying a
2009 Jun 02
3
valdate_presnce_of email, :if => :validate_id + Factory girl
Hi
In the model I have User
attr_accessor :validate_email_id
validates_presence_of :email ,:if => :validate_email_id
Could anybody please tell me how can I define a Factory for the above?
Thanks in advance
Sijo
--
Posted via http://www.ruby-forum.com/.
2009 May 25
1
Help --- My phone number field saves blank
I have a phone field in my table.
But in my form i have two text boxes to get the phone number and the
country code like below
Enter country code ----- Enter phone code ------
In my table i have to save the phone code field after joining the above
values with "-" symbol.
Example => 0225-25874255
I dont have table field for country_code .
So i created like below
attr_accessor
2006 Aug 10
4
I need "validates_presence_of" help
Hi - I have 3 fileds a user can fill out. They can fill out 2 of them or
just one of them, for example.
fill out these 2 fields:
Field1 and Field2
Or fill out this field:
Field3
In my model how do I use validates_presence_of for Field1 and Field2 or
just Field3.
I want to do something like this:
validates_presence_of Field1, Field2
OR
validates_presence_of Field3
So the user can fill out
2006 Jan 14
1
form fields WITHOUT table columns? Can we validate these in the model?
I would like to have a field on a form that does *not* have an underlying
column in the table.
Yet I would like to perform some validation on the value. I would like the
results of the validation to show up
just like the validations that are performed in the model.
This is very similar to the password_confirmation field on a sign up screen.
The password_confirmation is
there on the screen, but
2006 May 14
0
problem with validates_presence_of :on=> :update
I''m having what''s probably a stupid-newbie problem with validates_presence_of and I''m hoping someone will point me in the right direction.
Bottom line is that validates_presence_of does not seem to be ''firing'' when I use the :on => :update option. If I don''t include the option, the validation does fire.
The problem is that I want to
2005 Feb 19
0
[Error] Using validates_presence_of for datetime field causes parse error?
Hi Everyone -
I''ve got an odd sort of error when I try to use validates_presence_of
for a MySQL ''datetime'' field. Here''s the relevant portion of the table
definition:
mysql> describe student_surveys;
+---------------------+---------------------+------+-----
+---------------------+----------------+
| Field | Type | Null |