similar to: allow_empty instead of allow_nil

Displaying 20 results from an estimated 5000 matches similar to: "allow_empty instead of allow_nil"

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 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 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_validation
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:
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 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
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
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:
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])
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
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 Jan 30
9
Something as after_successful_validation?
I need to call callback only if the validation was successful, but it seems it is called also when validation fails. -- Posted via http://www.ruby-forum.com/.
2007 Aug 23
6
controller spec with model that validates_uniqueness
I want to use mocks and stubs to test the controller, but am having trouble getting my validation not to trigger. Here''s the code: # spec: Image.stub!(:find).and_return(@image) @image.should_receive(:save!).once.with(:any_args) put :update, :id => @image.id, :category_id => @category.id, :image => {:name => ''test'', :image_number =>
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
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
2006 Mar 01
5
validations without AR - going crazy trying to find link
Hi, in the past few months someone posted an entry on their blog about how to do validations in non-AR classes and I cant find it any more. Anyone have a link? Thanks, Trevor -- Trevor Squires http://somethinglearned.com
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
2005 Apr 25
0
nil instead of empty string
Is there a simple way to force a text_field form helper to return nil instead of an empty string if the length of the string is zero? I am trying to do length validation that uses allow_nil, but unfortunately my database is being populated with empty strings (using Microsoft SQL) I can write triggers to correct this behavior, but I am curious if it can be done easily within rails.
2006 Apr 04
3
model validates twice in tests, produces duplicate errors
In my unit tests for my User model, I''m testing some validation cases. What is really strange, and driving me crazy, is that in the unit tests, it seems like the save method is causing my validations to execute twice, and produce duplicate error messages. This is making my tests fail (because I''m checking for the number of errors that I expect). In the web browser, only one error