Displaying 17 results from an estimated 17 matches for "allow_blank".
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:
"ActiveRecord::RecordInvalid: Validation failed: Game has already been
taken"
I already have have specified that I want t...
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
2010 Jun 15
8
Allow blank on should validate_uniqueness_of
Hello,
Using shoulda, any ideas how to allow blank when having this test:
should validate_uniqueness_of(:email)
Thanks.
--
J. Pablo Fernández <pupeno-GAtDADarczzQT0dZR+AlfA@public.gmane.org> (http://pupeno.com)
--
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
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
2010 Feb 10
6
validation problems
Hi, there.
I have two validations in the model:
validates_numericality_of :value, :only_integer=>true,
:allow_blank=>true
validates_size_of :value, :is=>9, :message=>"must be 5-digit number",
:if=>Proc.new{|u| u.value.is_a?(Numeric)}
They work as expected except when the :value is character/string like
"a" "abc", the second validation will also output error message &quo...
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
2007 Nov 20
1
:allow_nil validation vs. blank?
...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 unrailslike. someone straighten me out please...
thx - mike
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Gr...
2008 Nov 17
7
super global dummy method for gettext + rails 2.2
Hi,
since rails 2.2 doesn''t work with gettext anymore I decided to use a
gettext dummy method until the gettext team relases a working version
for rails 2.2. My application doesn''t need any i18n support right now
and this way i figured it would be very easy to integrate gettext
later. Just setup the plugin and go.
So I need a method called _ which is available in alle models,
2013 Jun 23
1
Contact form - NoMethodError (undefined method `each' for nil:NilClass)
...Servicemail
include ActiveModel::Validations
include ActiveModel::Conversion
extend ActiveModel::Naming
attr_accessor :name, :email, :subject, :body, :szolg
validates :name, :email, :subject, :body, :presence => true
validates :email, :format => { :with => %r{.+@.+\..+} }, :allow_blank =>
true
def initialize(attributes = {})
attributes.each do |name, value|
send("#{name}=", value)
end
end
def persisted?
false
end
end
This is the controller:
class ScontactController < ApplicationController
def new
@message = Servicemail.new...
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
2011 Apr 21
1
Rails 3 Foreign Domain routing - cannot get this to work!
...ource :project
end
end
root :to => "home#index"
[/code]
in my model I have:
[code]
# app/models/project.rb
before_validation :cache_domain
validates_uniqueness_of :subdomain,
:cached_domain
validates_uniqueness_of :cname_alias,
:allow_blank => true
validates_presence_of :subdomain,
:cached_domain
validates_exclusion_of :subdomain,
:in => %w(admin blog),
:message => "is taken"
def cache_domain
self.cached_domain = if self.cname_alias.blank...
2010 Aug 18
7
error_messages_for doesn't work
I''m having a problem, ''cause I wrote the following line in my model
"Hi":
[code]
validates_numericality_of :phone, :only_integer => true, :allow_blank =>
false, :message => "must be a number"
[/code]
And in my "new" view, I put:
[code]
<%= error_messages_for :oi,
:header_message => "Erro ao cadastrar usuário." ,
:message => "Cheque o(s) seguinte(s) campo(...
2009 Jul 06
1
authlogic and updateing a user without changing password
...what have you. In my admin section I''d like to change only the state of
users. The problem is that when I submit the form, I get the following
error: Password can''t be blank
How to tell authlogic to not care about this error? Is it possible to
provide te à-la restful_auth option :allow_blank => true ?
Regards
--
Posted via http://www.ruby-forum.com/.
2012 Jul 19
0
New Gem: validation_hints
...ed in the user interface, for
instance for displaying a tooltip or other context-sensitive help.
It''s very crude yet but it works for the basic (built-in) validations
(Rails 3.2.3). It does not work with Custom Validators yet and also doesn''t
take in account some options like :allow_blank.
I welcome improvemets and other reactions, and hope similar functionality
will be added to AM/AR.
Cheers
ace suares
--
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-talk-/JYPxA...
2010 Aug 18
0
paper clip plugin validation fails
...ender }
end
here is the model validation
validates_attachment_content_type :picture,
:content_type=>[''image/jpeg'', ''image/png'', ''image/gif''], :message =>
:missing_content_type
or
validates_format_of :picture,:allow_blank=>true, :with =>
%r{\.(gif|jpg|png|jpeg|bmp)$}i,:message => "Invalid file extension for
teaser image. Please upload files with the following extensions only :
.jpg, .jpeg, .png, .gif, .bmp"
can anyone help me to sort out this issue.please help me
Thanks In advance
--
Post...
2009 Dec 31
1
Single Validation Error... best practices?
So a lot of Rails apps (mine included) have multiple validations on a
single attribute. For example: on the password field, validating that
it is (a) not blank, (b) matches the confirmation, (c) is at least X
characters long, and (d) contains at least 1 alpha and at least 1
numeric character.
The problem is: if that field is blank, the default errors shows all
four. That''s a little
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