Displaying 20 results from an estimated 50000 matches similar to: "Validate all model fields with validates_numericality_of"
2008 Apr 04
6
validates_numericality_of :not_equal_to
I have a situation in which I want to validate a number is not zero.
Both positive and negative values are acceptable, just not zero.
validates_numericality_of has an :equal_to attribute, but I don''t see a
:not_equal_to. I have not yet been able to find anyone who has
discussed this. I did find information about custom validators, so I am
now using a custom validator to check the field
2009 Jun 24
2
At my wits end ! Controlling passed in negative values from a form
Hi,
I am trying to validate a numeric value passed in from a form, which
is saved in a MySQL db as decimal(9,2)
Now problem is I need to ensure people don''t enter a form value like -.
003. In my validations, I have a validates_numericality_of check being
done. Furthermore, in validate method, I have a check using an if
statement such as :
((an_object[n].nil? or an_object[n] < 0) and
2008 May 11
0
validates_numericality_of and greater_than* doesn't appear to be working
I''m using Rails 2.0.2 and I have been trying to take advantage of the
"validates_numericality_of" with the ":greater_than" option with
something like this:
validates_numericality_of :users, :greater_than => 0, :only_integer =>
true, :allow_nil => true, :message => "The number of allowed users
must be a whole number greater than zero."
But this
2006 May 31
1
ActiveRecord: When / where to validate data? Tricky question
First of all, thanks for you time. I have kind of a tricky question and
wanted to see what you guys thought.
-------------------------------------------
Lets say I have this:
-------------------------------------------
class Purchase < ActiveRecord::Base
validates_numericality_of :some_number, :only_integer => true
end
-------------------------------------------
Then I do this:
2006 Jan 19
7
validates_numericality_of positive integer
Hi,
What is the simplest way to validate a positive integer?
validates_numericality_of :foo, :integer_only => true
how do I add the positive part? Do I need another validation statement
for pattern matching or do I have to write a validate() funciton for
my model?
Thanks,
Peter
2008 Mar 28
0
Patch review request: validates_numericality_of does not replace option in custom message like in default message
Hi,
Today someone created a ticket for a defect in
validates_numericality_of, at first sight i thought it wasn''t a defect
but an enhancement. But then i found that validates_length_of accepts
:message => "should be greater than %d", but validates_numericality_of
doesn''t (The output for v_n_o is: "should be greater than %d" instead
of "should be
2006 Jul 11
1
Validating composed_of
Hi,
How do I validate a composed_of attribute in my model?
I have a product model with:
composed_of :price, :class_name => ''Money'', :mapping => %w(cents cents)
This maps the price attribute to the Money
(http://dist.leetsoft.com/api/money/) class. I want to make sure that
the price only contains a price to 2 decimal places i.e. 1.25. This is
because if someone enters
2006 Apr 03
4
validates_numericality_of, :allow_nil => true?
Is there a way to use validates_numericality_of and still allow null
values?
I have a model with some optional values that can be nil, but if they''re
present, they must be numbers. Will I need to construct a custom
valiation for this, or is there some method built in? Seems like it
would be a common enough need.
Jeff
--
Posted via http://www.ruby-forum.com/.
2006 Feb 28
0
Confusion with counter and single table inheritance
I''m having trouble getting the magical counter to work in a rails app
with single table inheritance.
following is the relevant code.
thank you
class declarations
class Job < ActiveRecord::Base
has_many :vents
end
class Vent < ActiveRecord::Base
belongs_to :job, :counter_cache => true
validates_numericality_of :width
end
class Rectangular < Vent
2006 Dec 16
2
Validate some fields only on object creation, not update
I''m having a problem with my User model. Originally I had alot of
validation, including this:
validates_presence_of :password_confirmation, :password
validates_length_of :password, :within => 4..50
validates_confirmation_of :password
However, this made it impossible to edit a user without setting his
password, which I don''t want. So I tried to isolate the above
validations
2007 Nov 03
3
Birthdate validation
Hello everyone,
I''m almost cracking my head trying to do this birthdate validation. It
turns out that I can only accept users with at least 18 years old and
I''m trying to validate it writing this code on my user.rb fil at app/
models
class User < ActiveRecord::Base
validates_presence_of :full_name
validates_presence_of :street_address
validates_presence_of :city
2008 May 16
3
radio button observe field only triggers once
Hi,
If i add field observers to radio button fields they trigger once but
then nothing after that. I have multiple fields in a form that i need
to know if one of them changes and which spedific field. Below is an
example of two foelds i tested and they trigger once with the alert but
then nothing after that. I also tried individual observers for each
field test_yes and test_no but with the same
2006 May 19
2
Problems with belongs_to table joins
I am looking for a little assistance with a problem I have with a simple
table join using Rails. I am a relative newbie to both Ruby and Rails so
any help would be greatly appreciated . I have two tables products and
product_formats.
create table products (
id int not null auto_increment,
title varchar(100) not null,
product_format_id integer
2006 May 17
0
How to validate in_place_edit updates
Can anyone enlighten me on how to make in_place_edit fields go through validations that are defined in the model? For example, my customer model has a "validates_numericality_of phone", but when the in_place_edit is done you can enter whatever you want. The field is defined as a string in the DB. I can''t change the database schema, due to other constraints, so I need a
2006 Dec 06
2
validates_uniqueness_of where scope euqals created_by "magic" field
I have the following ActiveRecord objects:
class Recipe < ActiveRecord::Base
has_many :ratings, :dependent => true
. . .
end
class Rating < ActiveRecord::Base
validates_uniqueness_of :created_by, :scope => :recipe_id
belongs_to :recipe, :counter_cache => true
. . .
end
The created_by field on Rating is implemented as a "magic" field
similar to this:
2006 Jun 07
1
Validating numericality based on related attribute value?
I have a price attribute in my model which I need to validate as a
positive number if the attribute price_terms.requires_value is equal to
''Y'', otherwise price can be blank or zero. Price_terms is a select list
which my model table belongs_to.
How do I do this? - I tried doing this:
validates_numericality_of :price, :if =>
self.price_term.requires_value.upcase ==
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 Jun 21
3
validation help
I would like to validate a number within a certain range.
To first test that a entry is a valid number i use
validates_numericality_of :my_number, :message =>''sorry, not a number''
to test if the number is within a certain range i use
validates_inclusion of :my_number, :in => min..max, message => ''outside
range!''
If the numericality test fails, I
2006 Aug 16
3
Validate your forms with a table-less model
Ive followed this example of how to validate a form with a tableless
model:
http://rails.techno-weenie.net/tip/2005/11/19/validate_your_forms_with_a_table_less_model
Ive got this example working but when validation fails the failed boxes
are not highlighted in red. At the moment i have a contact details form
and want to validate the information entered by the user but this will
just result
2006 Jun 19
3
newbie validation
hi there. Here is the simple scenario:
My active record connects to a table that contains an integer field.
My form contains a text box that allows me to enter a value to get
updated to the integer field.
If anything gets entered that is anything other than a POSITIVE INTEGER,
I want to display an error.
I have noticed that if I create a new active record like
@record =