Displaying 20 results from an estimated 100000 matches similar to: "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 
field to be submitted. However, if :year is
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,
        
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
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 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
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
 
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
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
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"]
     
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
2007 Sep 27
1
How to call a model object method for validation?
This is the code I''m trying to get to work:
  validates_inclusion_of    :status,
    :in => poll_statuses().keys
  def poll_statuses
    return {
      "closed" => "Closed",
      "open" => "Open"
    }
  end
It says there''s no poll_statuses method in Poll.  How do I access this
method?  I''ve tried
2006 Nov 20
1
Getting started with ActiveMerchant & new Ecommerce book
Hi there
I''ve got a copy of the ''Beginning Ruby on Rails Ecommerce'' book and am
trying to integrate ActiveMerchant into my app.
My order.rb file has the line:
''include ActiveMerchant::Billing''
per the book.
My Order model also has, amongst other things, the following validation:
''  validates_inclusion_of :billing_country, :in =>
2007 Dec 17
9
Rails 2.0.2: Some new defaults and a few fixes
Now that we have the big Rails 2.0 release out the door, it''s a lot
easier to push out smaller updates more frequently. So that''s what
we''re going to do. Rails 2.0.2 contains a bunch of smaller fixes to
various bugs, no show-stopping action, just further polish. But it
also contains a few new defaults:
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:
2007 Oct 13
4
Chapter 9
Hello,
I''m currently stunk on this issue for few days and I do not know how
to get it fixed.
The system always raises  this error message :
order is closed
and here is my order.rb:
class Order < ActiveRecord::Base
include ActiveMerchant::Billing
  before_validation :set_status
 
attr_protected :id, :customer_ip, :status, :error_message, :updated_at, :created_at
 
attr_accessor
2007 Feb 02
3
rails command version pegging?
Hello,
Is it possible to declare the version of Rails used with the seminal 
"rails /path/to/my_app" command?
For example, I now have 1.2.1 and 1.1.6 installed on my machine.  If I 
run "rails my_app" I get 1.2.1 produced skeleton code.  Is there a way 
to get 1.1.6 results?
Regards,
Andy Koch
--~--~---------~--~----~------------~-------~--~----~
You received this
2007 Dec 27
0
Silent Validation Failures
Hello,
I''m having trouble with after_validation_on_create causing my
validations to fail silently.  I''ve got a restful_authentication based
user model that requires a number of things from the user: email, dob,
gender, etc.  When a user is created, all of these are validated in
various ways (presence, inclusion_of, etc.).  Afterwards, I call three
protected methods using
2007 Jul 06
2
validations of "type" when using Single Table Inheritance
Sorry if I''m just dumbing out, but is there a reason that when using
Single Table Inheritance Rails doesn''t really validate the "type"
field 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
     
2009 Aug 06
6
Maddening error: "marshal data too short"
I''m occasionally getting an odd Rails error that says "marshal data
too short".
Our entire web app seems to be working fine -- we can post forms, save
models, redirect, login, etc, without any problems.  Then out of
nowhere a request will result in the 500 error "marshal data too
short".  Subsequent requests to *any* page then result in the same
error -- even pages
2008 Jul 17
2
problems with validation on STI
I have the following STI table:
def self.up
    create_table :distributions do |t|
      t.string :type
      t.integer :simulation_id
      t.string :dist_name
      t.string :desc, :default=> ''fixed''
      t.float :param1, :default => 5.0
      t.float :param2, :param3
      t.timestamps
      #fields for RscDist
      t.integer :resource_id
      #fields for LoadDist