Displaying 19 results from an estimated 19 matches for "only_integ".
Did you mean:
only_integer
2006 May 31
1
ActiveRecord: When / where to validate data? Tricky question
...st 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:
-------------------------------------------
purchase = Purchase.new
purchase.some_number = ''This is not a number''
Right now the data is not correct. Is this ok? Why should I even let
invalid data like...
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...
2007 May 05
10
have_one and have_present
...but it still ''speaks'' better than ''have_present'' for me.
FYI - Jay Fields has a Validatable framework that includes some
test/unit assertions that look like this:
Foo.must_validate do
presence_of :name
format_of(:name).with(/^[A-Z]/)
numericality_of(:age).only_integer(true)
end
Because Spec::Rails behaviours inherit from Test::Unit::TestCase, you
can install the validations gem (gem install validatable) and use
these as/is with RSpec. Or, if you want it to feel more spec''ish, you
could monkey patch an alias:
Foo.should_validate do
presence_of :na...
2006 Aug 14
1
What fields_for really for?
...one!
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 region_id.
There is no region_id in suburb model so first I added these lines to
it:
...
class Suburb < ActiveRecord::Base
belongs_to :district
attr_writer :region_id
def region_id
district.region_id if district...
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 doesn''t seem to be catching values set to zero or negative
values.
Am I using this correctly?
NOTE: I have the same problem with the ""...
2007 Jan 18
2
Conditional validates_inclusion_of execution problem
All,
I have a field that I''m validating with validates_numericality_of on as
well as validates_inclusion_of, like so:
validates_numericality_of :number_of_owners,
:only_integer => true,
:message => ''must be a whole number''
validates_inclusion_of :number_of_owners,
:in => 1..3,
:message => ''should be between 1 and 3'',
:if => P...
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 =
2007 May 01
2
Problem validating boolean
...ere''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 :term, :only_integer => true
validates_inclusion_of :linked_to_residual_value_of_asset, :in
=> [true, false]
end
and here''s the RSpec code I''m using to test it:
context "A FinanceAgreement with valid attributes" do
setup do
@finance_agreement = FinanceAgree...
2006 Jun 07
1
Setter that converts a float attribute to integer
...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, and the corresponding
accesors:
class Report < ActiveRecord::Base
validates_numericality_of :price, :only_integer => true
attr_accessor :price_in_euros
def price_in_euros
if self.price
self.price / 100.0
else
# default price is 1 euro
1
end
end
def price_in_euros...
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 usuário." ,
:message => "Che...
2006 Jun 07
2
Problem with a setter that converts euros to cents
...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, and the corresponding
accesors:
class Report < ActiveRecord::Base
validates_numericality_of :price, :only_integer => true
attr_accessor :price_in_euros
def price_in_euros
if self.price
self.price / 100.0
else
# default price is 1 euro
1
end
end
def price_in_euros=(euros)
self.price = (euros * 100).to_i
end
end
If I test this model with the rails console, all is working fine:
$...
2005 Dec 17
0
bug? saving (valid) updated object results in validation error
...validates_associated :product
> validates_presence_of :voucher
> validates_presence_of :price_sold
> validates_uniqueness_of :voucher
> validates_length_of :voucher, :within => 10 .. 50
> validates_numericality_of :price_sold
> validates_numericality_of :voucher, :only_integer => true
> validates_each :price_sold do |rec, s, t|
> t ||= 0; rec.errors.add s, "negative price" if t < 0
> end
Using script/console as follows:-
> >> c = Coupon.find :first
> => #<Coupon:0x24d3e64 @attributes={"created_on"=>nil,...
2011 Sep 04
0
should validate_numericality_of with greater_than_or_equal_to
...equal_to(0) }
NoMethodError:
undefined method `greater_than_or_equal_to'' for
#<RSpec::Matchers::Matcher:0xef23150>
this page
http://remarkable.rubyforge.org/activerecord/classes/Remarkable/ActiveRecord/Matchers.html
has method
it { should validate_numericality_of(:age).only_integer }
and :less_than_or_equal_to is a valid option..
I am confused. How do I spec this? thanks.
2006 Jun 28
3
how do I validate currency format if I am storing in cents?
Hi all -
To avoid floating point issues, I''ve decided to store monetary values in
cents in the database. However, the user will enter these in dollars
and cents. Two questions:
1) How do I do the validation for the currency format? It looks like
ActiveRecord truncates the cents since it thinks the field type is a
Fixnum. Am I forced to do validation in the controller?
2) Where
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 13
7
model validation across multiple views
I have a rather complex object with a number of attributes. For a variety
of reasons, I would like one view to create the object with only a couple of
fields completed, then a second and third view to finish all the fields. I
would like the model to validate_presence_of all these fields, since
eventually I need them all there, and I would like each page to validate its
portion of the fields that
2008 May 17
12
validates_numericality_of with greater_than* less_than* simply don't work
It seems that the validations for:
greater_than
greater_than_or_equal_to
less_than
less_than_or_equal_to
equal_to
odd
even
Simply do not work (Rails 2.0.2). I''ve tried every combination I can
think of and these never seem to fire.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby on Rails:
2006 Jun 06
15
error working through Agile !!!
Hi everyone,
I''m working my way thru the ''Depot'' project from Agile Web Development
with Rails.
I got to the bit where I type:
ruby script/generate scaffold Product admin
And I get the following error:
error Before updating scaffolding from new DB schema, try creating a
table for your model (Product) ( on the last line ! )
Now I have followed everything as
2006 May 23
11
putting the schema in the model files
THE SCHEMA IN THE MODEL
a small write up on ''putting the schema in the model''
This is a write up on an issue best covered in a mailing list thread
of Januari 2006 (see the links in the text), I repost it because I
think it deserves a place on the agenda.
== Why? ==
I was switching back and forward between the model files and the
schema.rb -- off course I have