search for: allow_nil

Displaying 20 results from an estimated 36 matches for "allow_nil".

Did you mean: allow_bit
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 post to this group, send email to rubyonrails-tal...
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/.
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 through params every time i do a create/update to convert blank to nil. totally unrailsl...
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 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, i...
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
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
...re_badge.game_id = nil genre_badge.save! It creates an validation exception: "ActiveRecord::RecordInvalid: Validation failed: Game has already been taken" I already have have specified that I want to allow_blank. I really don''t know why I get the validation error. I also tested allow_nil but got the same error. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane...
2006 Nov 04
0
Validations ignoring :allow_nil => true
I have an address model and am doing some validations. One of them seems to ignore :allow_nil => true. If I leave the phone input blank, I get it back with a "too short" error. Here''s the relevant parts of the model: 1. class Address < ActiveRecord::Base 2. 3. validates_length_of :phone, :in => 7..10, :allow_nil => true 4. 5. before_vali...
2007 Dec 27
4
validates_file_format_of only when is there an image
i have a model with this: file_column :image validates_file_format_of :image, :in => ["gif", "png", "jpg"] If inthe form the user not insert the image i receive an error. If i remove: validates_file_format_of :image, :in => ["gif", "png", "jpg"] it works. Is possible do the validation only when user insert the image in form? i
2007 Mar 29
4
validates_length_of not working with :if ?
Hello, I''m trying to cut down the errors if the guy already getting the empty nickname, so he doesn''t get anything about the nickname is short. validates_presence_of :nickname This below is not working ? validates_length_of :nickname, :within => 4..40, :if => Proc.new { |user| user.nickname.length > 1 } nor this one below? validates_length_of :nickname, :within
2006 Mar 10
2
validation null objects and objects with data
I have a model where initially, they we don''t insert an gov_id value because it isn''t known. The field is given a value of "" because it is on the form. I then added code to the ''create'' method to set that value to nil if it is blank which seems to be fine but then it fails this validation (if NULL) validates_length_of :gov_id, :maximum =>
2006 May 18
1
Patch 5091
...n 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 Summary: extra option :allow_nil for composed_of allows nil attributes in aggregations. Currently aggregations do not allow nil attributes. This means that if you want an optional aggregation in your model you must code this into your component class. This is, in most cases, a defect. For example, you may want an optional gps_lo...
2007 Aug 23
6
controller spec with model that validates_uniqueness
..._return(@image) @image.should_receive(:save!).once.with(:any_args) put :update, :id => @image.id, :category_id => @category.id, :image => {:name => ''test'', :image_number => 13554} #model validates_presence_of :name validates_uniqueness_of :name, :allow_nil => true # rspec output ActiveRecord::RecordInvalid in ''ImagesController should update a database record when it receives a PUT'' Validation failed: Name has already been taken, Image number has already been taken It seems AR is not detecting that this is an edit/update t...
2007 Jul 06
2
validations of "type" when using Single Table Inheritance
...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 derived class) Thanks! --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to th...
2006 Apr 27
0
DRY validation
...a.validates_format :with => /\A[A-Z]+\z/ a.validates_uniqueness end attribute :code_alpha3, :string do |a| a.validates_length :is => 3 a.validates_format :with => /\A[A-Z]+\z/ a.validates_uniqueness end attribute :phone_code, :integer, :allow_nil => true do |a| a.validates_numericality :greater_than_or_equal_to => 1, :less_than_or_equal_to => 9999 end end The advantage of this it DRYs up the validation rules since you don''t have to specify the name of the attribute over and over. Plus it automatically set...
2006 Jan 30
1
Either/Or Validation
How would I use validations to ensure I either received a blank value or a ten digit number? If I set validates_length_of :field, :in => 0..10 then that would allow any value in-between. The allow_nil => true option does not seem to work. I''ve also tried using this with some combination of validates_numericality_of but cannot get it to work. Any help would be greatly appreciated. Thanks, Josh -- Posted via http://www.ruby-forum.com/.
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 "" option so I assume it i...
2007 Mar 09
2
Blank fields getting validated
Hi, I am not sure if this is already answered in this list. I couldn''t find an answer. So I am posting the question. I have multiple validations for a field. For example: validates_presence_of :contact_email validates_format_of :contact_email, :with => /^([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})$/i, :message => "is not a valid email
2011 Dec 13
3
Validates presence
Hi everyone, I just need a quick help :) What is the best way to write some code in :presence option? I have a Question model and one of the fields is question_type: - example question - static question Each question has alternatives, and each of them has scores What I want is to validate the presence of :score, but when its only on the static question. I dont want to validate the presence