Displaying 20 results from an estimated 700 matches similar to: "Conditional validates_inclusion_of execution problem"
2007 May 01
2
Problem validating boolean
Hi
I''ve got a problem validating a boolean and I can''t see what the
problem is. Here''s my model:
class FinanceAgreement < ActiveRecord::Base
belongs_to :asset
validates_presence_of :finance_company
validates_inclusion_of :balance, :in => 0.01..10_000_000
validates_inclusion_of :term, :in => 1..600
validates_numericality_of
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 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:
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
2006 Aug 14
1
What fields_for really for?
Hello everyone!
I have 3 models:
=== 1 ===
class Region < ActiveRecord::Base
has_many :districts
end
=== 2 ===
class District < ActiveRecord::Base
belongs_to :region
has_many :suburbs
end
=== 3 ===
class Suburb < ActiveRecord::Base
belongs_to :district
validates_numericality_of :region_id, :only_integer => true
end
In edit.rhtml for SuburbController I need to specify
2006 Apr 08
4
Calling validates_inclusion_of out of default namespace
Hi,
I''m trying to run the "validates_inclusion_of" method in a before_save hook,
because the range is dependant on the related data. But I can''t figure out how
to call it. When calling it normally, it says it can''t find it.
I''ve tried several combinations like
"ActiveRecord::Validations.validates_inclusion_of", but I can''t seem to
2006 Feb 14
2
confusion with validates_inclusion_of
It appears that if your trying to use validates_inclusion_of for a
string value allow_nil wont work. For example, if I have an attribute
:year which is stored as a varchar then:
validates_inclusion_of :year, :in => "1980"..Time.now.year.to_s,
allow_nil=>true
will successfully validate the range but will not allow an empty input
field to be submitted. However, if :year is
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
2011 Feb 16
5
validates_inclusion_of with range on ruby 1.9
I found out today that Range#include? behaves differently on 1.9 than on 1.8 ( http://rhnh.net/2009/08/03/range-include-in-ruby-1-9 )
In order to deal with various edge cases, instead of just checking whether range.first <= value <= range.last, in ruby 1.9 include? steps through all the values in the range, checking for equality.
This is of course a lot slower - in my case, checking a date
2010 Feb 10
6
validation problems
Hi, there.
I have two validations in the model:
validates_numericality_of :value, :only_integer=>true,
:allow_blank=>true
validates_size_of :value, :is=>9, :message=>"must be 5-digit number",
:if=>Proc.new{|u| u.value.is_a?(Numeric)}
They work as expected except when the :value is character/string like
"a" "abc", the second validation will also output
2007 Jan 17
2
rake test and validates_inclusion_of
Hello,
I am just starting off with Rails, so I apologize in advance if there
is a terribly obvious answer to my problem. I''ve done some searching
and found similar problems to my own, but nothing which yielded a
solution.
I have a handful of models that I am unit testing. The tests for each
unit run successfully, but when I do a rake test, many of the tests
fail.
The assertions that
2006 May 26
4
Using ''validates_inclusion_of'' to validate foreign key
I seem to be missing something trying to use ''validates_inclusion_of'' to
validate a foreign key and was hoping some one could piont out my
mistake?
The problem seems to be that Order.find_all.collect is not returning an
array that contains the order_id, if I replace it with a hardcoded array
everything works as expected.
The model:
class OrderItem < ActiveRecord::Base
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 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
2007 Mar 13
13
validates_inclusion_of disabling
Hello all.
I have a problem using validates_inclusion_of. I need to switch off some
validations during a migration period, is there a way?
I tried to use if, with a static method of one of my models, but the
behaviour is something strange
It seems that the static method should be in a string to be evaluated.
And the order of the elements in the if is counting...
:if => (:some_field
2011 Jun 19
10
validates_numercality_of with allow_nil.
In the model I have:
validates :square_meters_public_land, :barrier_meters, :numericality
=> { :greater_than_or_equal_to => 0 }, :allow_nil => true
but if, in the field, on create, I don''t insert a value I have the
error "field is not a number".
--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To
2005 Feb 09
1
[DEFECT] ''validates_inclusion_of'' not working as expected (couldn''t post to Trac as it gave me an error)
Hello,
I tried to post this as a bug on the trac site, but whenever I hit
submit, I got the error message:
---
Precondition Failed
The precondition on the request for the URL /newticket evaluated to false.
---
Anyway...
Let''s say I have the following model classes:
---
class Project < ActiveRecord::Base
has_many :tasks
end
class Task < ActiveRecord::Base
belongs_to
2006 Jun 07
1
Setter that converts a float attribute to integer
Hi,
I have some problems with an application where I''m using custom
accessors to do currency conversions. In my model, I have a price
attribute in the database that stores the value in cents, to avoid
future problems with float arithmetic and round. But at the views, I
would like to show the price in euros, with decimal for the cents. So
I defined a new attribute called price_in_euros,
2005 Dec 17
0
bug? saving (valid) updated object results in validation error
Hi!
I have an error that I don''t understand. It shouldn''t be happening,
according to the documentation! I have a class, defined as below.
> class Coupon < ActiveRecord::Base
> belongs_to :product
> belongs_to :account
> validates_presence_of :product
> validates_associated :product
> validates_presence_of :voucher
> validates_presence_of
2010 Aug 18
7
error_messages_for doesn't work
I''m having a problem, ''cause I wrote the following line in my model
"Hi":
[code]
validates_numericality_of :phone, :only_integer => true, :allow_blank =>
false, :message => "must be a number"
[/code]
And in my "new" view, I put:
[code]
<%= error_messages_for :oi,
:header_message => "Erro ao cadastrar