similar to: Validations ignoring :allow_nil => true

Displaying 20 results from an estimated 700 matches similar to: "Validations ignoring :allow_nil => true"

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
2006 Feb 02
1
allow_empty instead of allow_nil
Is trhere any way how to support allow empty? Rails prefer empty string than null for database and then validations with allow_nil fails. -- Posted via http://www.ruby-forum.com/.
2013 Apr 03
1
validates uniqueness scope allow_blank/allow_nil -> validation error
I have this in a model: class GenreBadge < ActiveRecord::Base belongs_to :game, counter_cache: :genre_badges_count, touch: true belongs_to :genre validates :game_id, uniqueness: {scope: :genre_id}, allow_blank: true end When I get one existing genre badge genre_badge = game.genre_badges.first genre_badge.game_id = nil genre_badge.save! It creates an validation exception:
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
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 08
4
gsub no workie
Don''t know why, but cant seem to get this to work for me. I have a phone number field for an addressbook. In the addressbook model I have a before_update declaration that says the following: I''d like to be able to remove all special characters (just numbers please), but this doesn''t want to work for me. before_update :format_phone def format_phone self.phone =
2003 Jul 23
0
pls.pcr compared to Unscrambler
Dear R-helpers, Has anybody ever tried to compare pls regression outputs from the pls.pcr R-package developped by Wehrens with outputs from the Unscrambler software developped by CAMO company ? I find very different outputs and wonder if this comes from differences between methods/algorithms SIMPLS (pls.pcr) and PLS1 (Unscrambler). Arnaud ************************* Arnaud DOWKIW Department of
2007 Apr 05
0
unexpected behavior of before_validation
Today I found these comments in active record''s callbacks.rb file: # If the returning value of a before_validation callback can be evaluated to false, the process will be aborted and Base#save will return false. # If Base#save! is called it will raise a RecordNotSave error. # Nothing will be appended to the errors object. This caused me a lot of frustration earlier when I was
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 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 May 09
11
model filter?
Hi All, Is there a way to filter / modify the output of a model class before it''s returned to controller/view that''s calling it? Example: I have a field phone_number which I always want to preformat using the number_to_phone() helper.... Any help is appriciated. Thanks! -- Posted via http://www.ruby-forum.com/.
2006 May 18
1
Patch 5091
Hi, I submitted a patch (for the first time) a couple of days ago (http://dev.rubyonrails.org/ticket/5091 - the decsription is included below). I''ve noticed some posts to rails-core notifying the world of patches, since there''s been no activity on said patch I thought I''d do the same. Please let me know if this breaks protocol. Cheers, Ian White --- patch summary
2006 Mar 24
1
Problems with before_validation
Hi all My visitors can create party organisator profiles, and I want assign them as the creators (the field creator_id in the organisators table references a member in the members table). To do that I tried it with before_validation: def before_validation creator = Member.find 1 end Sadly, this does not work. The validation validates_presence_of :creator_id Still tells me, that
2011 Jun 19
1
before before_validation callback
Hi, I was looking around a bit and couldn''t find any callbacks that executed before before_validation The current problem with using before_validation is that it won''t fire if I''m not using validations with #save(:validate => false) - which makes sense. Before_save won''t suffice because I want these callbacks to fire before validation on the occasions that
2005 May 04
1
Conditional validations
I''ve been working with the problem that Joe Hosteny has been talking about on this list and on the tickets he''s posted (http://dev.rubyonrails.com/ticket/1196) and have come up with a tentative solution that I''d like to bring up here. What if we use a "conditional" parameter in the validates_* methods? Here''s how it would look like in practice:
2006 Oct 22
2
Key colour problem with lattice plot
Hi, I seem to have a key colour problem with a lattice barchart. The colours on my key rectangle don't match the colours on the barchart. Here is my data frame: "LandFill" "Ruminants" "United States (USA)" 7777.21428 5528.16 "France" 200.527083 1299.87 "Australia" 185.878368 2448.17 "Russian Federation" 1752.8334 2024.29
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 Apr 27
0
DRY validation
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Hi all, A few months ago someone posted a message about specifying validates_* constraints on a per-attribute basis. I just created a small plugin that allows you to do this. Here''s an example from one of my models: class Country < ActiveRecord::Base attribute :name, :string do |a| a.validates_length :within =>
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 Nov 10
3
Move variables from session to ActiveRecord?
Buildings have units. Units have rooms. Rooms have people. I can grab building, room, and people IDs and store them in a session[:variable]. However, when creating a new unit, I need to give that session[:building_id] to ActiveRecord for creation. I''m not sure whether to use hidden fields or do it all in the model ''before_validation'' - in either case I