Displaying 20 results from an estimated 4000 matches similar to: "confusion with validates_inclusion_of"
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
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 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 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,
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
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
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
2007 Jul 24
13
Problem with validates_length_of an integer
Hello guys, I''m trying to validate the input of an integer from a form,
here is a bit of code:
This is the definition of the offending column in the migration:
t.column :position, :integer, :default => 0, :limit => 3, :null => false
And here is how I try to validate it inside de model:
validates_length_of :position, :within => 1..3
And this is the exception I get when I
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
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
2006 Jan 11
0
Easy Question, I Think
I am just getting started with Rails, don''t know any Ruby, and don''t
quite even get object oriented programming yet. I have tweaked my
schema to The Rails Way and have generated a bit of scaffolding.
I am trying to create a new Part, which references a PartName and a
PartNumber. I can create a PartNumber on the fly, but the PartName
has to exist. I have an inelegant solution
2006 Jan 12
0
Easy Question, I Think [re-post, sorry if dupe]
I am just getting started with Rails, don''t know any Ruby, and don''t
quite even get object oriented programming yet. I have tweaked my
schema to The Rails Way and have generated a bit of scaffolding.
I am trying to create a new Part, which references a PartName and a
PartNumber. I can create a PartNumber on the fly, but the PartName
has to exist. I have an inelegant solution
2007 Nov 20
1
:allow_nil validation vs. blank?
I think I must be doing something wrong... when a form returns params
to the controller, empty fields appear to be returned as blank, not
nil. so what''s the point of an :allow_nil=>true setting on a
validation? it fails because blank is not the same as nil.
i would expect either returned empty fields to be nil, or :allow_nil
to really be :allow_blank. otherwise i have to do a search
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
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 on this for me?
--~--~---------~--~----~------------~-------~--~----~
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
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
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
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"]