Displaying 20 results from an estimated 52 matches for "validates_inclusion_of".
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...
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
fie...
2011 Feb 16
5
validates_inclusion_of with range on ruby 1.9
...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 for inclusion in a 100 year Date range (via a validates_inclusion_of) went from instantaneous to over 100ms. I think this sort of thing is probably pretty common in rails apps and that the edge cases this change was designed to address are extremely unlikely to crop up with validates_inclusion_of - people are almost always going to be validating plain old strings, d...
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,
:m...
2007 Jan 17
2
rake test and validates_inclusion_of
...ew(:name => "super department",
:parent_id => departments(:administration_department).id)
assert department.save
When I print out department.errors, I see that parent_id is invalid
because it "is not included in the list".
The validation I have on parent_id is:
validates_inclusion_of :parent_id, :in => Department.find_all.collect {
|e| e.id }
So, maybe the department table wasn''t the best example because it''s
acts_as_tree, BUT all the failed assertions are the same:
- they''re failing on asserting that an object is good
- the object has a reference...
2006 Dec 15
4
Why won't Rails update my object attributes?
Here''s the issue: When I submit a form for updating,
@person.update_attributes doesn''t work. But the next nested clause for
updating images DOES work. How is that possible? However no matter
what I do the Person object will not change its attributes.
def edit
@person = Person.find(params[:id])
if request.post?
@person.update_attributes(params[:person])
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 &l...
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...
2007 Oct 13
4
Chapter 9
...length_of :ship_to_postal_code, :in => 2..255
validates_length_of :ship_to_country, :in => 2..255
validates_length_of :phone_number, :in => 7..20
validates_length_of :customer_ip, :in => 7..15
validates_format_of :email, :with => /^([^@\s]+)@((?:[-a-z0-9]+\.)+
[a-z]{2,})$/i
validates_inclusion_of :status, :in => %w(open processed closed
failed)
validates_inclusion_of :card_type, :in => [''Visa'', ''MasterCard'',
''Discover''], :on => :create
validates_length_of :card_number, :in => 13..19, :on => :create
validates_inclusi...
2006 Sep 14
0
validates_inclusion_of
Q: validates_inclusion_of does it''s validation *only* on save. Why is
that the case? Wouldn''t it make more sense to include update as well?
As is, I can only create an object with a valid column option, but I can
update the column to whatever. Seems a bit odd to me...
Any one able to shed some light...
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 :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 u...
2005 Feb 09
1
[DEFECT] ''validates_inclusion_of'' not working as expected (couldn''t post to Trac as it gave me an error)
...e:
---
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 :project
validates_inclusion_of :project, :in Project.find_all
end
---
You would expect the validation to work properly (Project.find_all
returns an enumerable), but Ruby complains of a syntax error when
performing the validation callback:
---
1) Error:
test_create(TasksControllerTest):
SyntaxError: compile error
/usr/local/rub...
2010 Dec 30
6
validates_inclusion_of doesn't match constant
Hello, I have a model Model:
SPECIAL_FEATURES = %w(none top)
class Model
validates_inclusion_of :special_feature, :in =>
Model::SPECIAL_FEATURES,
:on => :create, :message => "special_feature
%s is not defined"
belongs_to :team
def special_feature
attributes = attributes_before_type_cast
if attributes["special_feature"]
r...
2006 May 10
0
Boolean attributes - not so simple as I thought
...@attribs like this:
get: @item.attribs.each {|a| puts @item.send(a)}
set: @item.attribs.each {|a| @item.send(a.to_s + ''='', some_hash[a])}
in the get part the method that gets called by send is @item.bool and
not @item.bool?.
Another issue is validation: should I use
validates_inclusion_of :bool? , :in=>[false,true]
or
validates_inclusion_of :bool , :in=>[false,true]
or
validates_inclusion_of :bool , :in=>0..1
or maybe something else?
Can you please help me with these issues?
I am using Ruby 1.8.2 + Rails 1.0 + MySQL.
--
Posted via http://www.ruby-forum.com/.
2009 Jan 12
2
validates_presence_of fails with false boolean
This almost feels like a bug to me, since false is not nil. (i don''t
think!) Using v_p_o on a boolean field fails validation if the field is
passed with ''false''. It passes validation in the case of true. How can
I validate _presence_of a boolean if it is submitted false?
--
Posted via http://www.ruby-forum.com/.
--~--~---------~--~----~------------~-------~--~----~
2007 Jul 06
2
validations of "type" when using Single Table Inheritance
...ield or provide some mechanism to do so? seems like a good way to
corrupt a database. Because the "type" is also a special attribute, I
had to resort to an ugly hack like:
class ActiveRecord::Base
def type_attr
self[:type]
end
def self.validates_type(options={})
validates_inclusion_of :type_attr, options
end
end
so that I could write:
class Fruit < ActiveRecord::Base
validates_type :allow_nil => true,
:in => %w{ Apple } # could be dynamic
subclass_of but make faster!
(obviously this could also have been put on the derive...
2006 Jan 11
0
Easy Question, I Think
...-----Models--------------------
class Part < ActiveRecord::Base
belongs_to :part_name
belongs_to :part_number
has_many :part_years
has_many :part_details
has_many :part_comments
has_many :car_job_parts
validates_inclusion_of :side,
:allow_nil => true,
:in => %w{ L.H. R.H. }
validates_inclusion_of :quantity,
:in => 1..99
validates_presence_of :part_number_id, :part_name_id
validates_associ...
2006 Jan 12
0
Easy Question, I Think [re-post, sorry if dupe]
...-----Models--------------------
class Part < ActiveRecord::Base
belongs_to :part_name
belongs_to :part_number
has_many :part_years
has_many :part_details
has_many :part_comments
has_many :car_job_parts
validates_inclusion_of :side,
:allow_nil => true,
:in => %w{ L.H. R.H. }
validates_inclusion_of :quantity,
:in => 1..99
validates_presence_of :part_number_id, :part_name_id
validates_associ...
2005 Feb 13
5
Select Enumerated Values with FormOptionsHelper
Hey,
I''m new, so apologies if I''ve overlooked obvious resources or violated
any etiquette rules for this list.
Since rails does not support the MySQL enum data type, I''m following
David''s advice of using a varchar and storing the valid values in the
application:
http://one.textdrive.com/pipermail/rails/2005-January/001536.html
So here''s my
2009 Jun 24
2
At my wits end ! Controlling passed in negative values from a form
...so:
self.xxx = 0 unless self.xxx
(where xxx is name of attribute)
I have tried checking for a minus sign in before_validation & validate
method using xxx.to_s.include?("-"). I have also tried
using :greater_than and :minimum options in the
validates_numericality_of call. I also tried validates_inclusion_of,
giving a range from 0..9999999.99.
Nothing seems to work.
Would appreciate any insight into this ! ? What am I missing ??
Thank you