Displaying 20 results from an estimated 91 matches for "validates_length_of".
2007 Oct 13
4
Chapter 9
...chant::Billing
before_validation :set_status
attr_protected :id, :customer_ip, :status, :error_message, :updated_at, :created_at
attr_accessor :card_type, :card_number, :card_expiration_month, :card_expiration_year, :card_verification_value
validates_size_of :order_items, :minimum => 1
validates_length_of :ship_to_first_name, :in => 2..255
validates_length_of :ship_to_last_name, :in => 2..255
validates_length_of :ship_to_address, :in => 2..255
validates_length_of :ship_to_city, :in => 2..255
validates_length_of :ship_to_postal_code, :in => 2..255
validates_length_of :ship_to...
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 => 4..40, :if => nickname.length
> 1
Anyone have a solution for this?
Thanks :)
--
Posted via http://www.ruby-forum.com/.
--~--~------...
2012 Aug 14
3
validates_format_of :message not working, validates_length_of :message is working
...do works, but I
can''t get an error message to be displayed if the data is invalid:
validates_format_of :mobile, :with => /\A[\+0-9]+\Z/, :message => " - Wrong"
I have another validation some where else that does display the error
message: " - Name is too long"
validates_length_of :name, :within => 5..40, :too_long => " - Name is too
long",
validates_length_of :name, :within => 1..50, :message => "Broken" *<------
This also works but not for validates_format_of*
Any ideas?
Thanks.
--
You received this message because you are subscrib...
2006 Aug 17
2
validates_length_of with char field
I am new to ruby/rails and am having a problem with validates_length_of.
It seems to work fine on a varchar field, but when I try it on a char
field the extra characters are silently truncated and the message
appears that the record was successfully updated.
How can I get my app to produce my error message instead? I''ve tried
various variations, but here&...
2007 Jul 24
13
Problem with validates_length_of an integer
...uys, 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 submit the form:
NoMethodError
private method `split'' called for 0:Fixnum
Maybe I''m not supposed to validate the length of integers at all?
--
Posted via http://www.ruby-forum.com/.
--~--~---------~--~----~-...
2005 May 29
0
validates_length_of && validates_presence_of: Duplicate error messages?
validates_presence_of :login , :on => :create, :message => "Please
enter a login."
validates_length_of :login, :within => 3..40, :message => "Login must
be a minimum of 3 characters."
Right now if the login field is left blank, both these errors get
thrown. I assume that setting a conditional for the first one if the
second one is thrown, something like
validates_length_of :logi...
2006 May 09
5
How to use gettext in plugins?
I use rails-engine as a plugin of the application and I want to localize
the validate message from the plugin:
validates_length_of :login, :within => 3..40, :on => :create, :message
=> N_("%{fn} is too short (min is %d characters)")
It can not display the according language,where should i set it?
I have tried to add
require ''gettext/rails''
GetText.bindtextdomain("myd2d")
to init...
2006 Jan 20
3
Is there a way to validate a model w/o saving it?
...:subdomain, :on => :create, :message => "is
already being used"
validates_exclusion_of :subdomain, :in => %w{ www blog weblog forum
info }, :message => "invalid subdomain"
user.rb
validates_presence_of :login
validates_uniqueness_of :login, :on => :create
validates_length_of :login, :within => 3..40
validates_confirmation_of :password, :if => Proc.new { |u|
u.password.size > 0}
validates_length_of :password, :within => 5..40, :on => :create
My problem is that if there are issues with the user validation, the
account has already been saved, so when t...
2005 Dec 29
0
UTF-8 and validates_length_of
Hello,
according to
http://wiki.rubyonrails.com/rails/pages/HowToUseUnicodeStrings
Rails is not ready for UTF-8 in many places, e.g. the
validates_length_of method. However, I see UTF-8 used in many Rails
applications. So, hopefully, is the wiki page now out-of-date?
Cheers,
Nils
--
Posted via http://www.ruby-forum.com/.
2006 Jun 12
2
conditional validation
Hi how can I validate a field only if another field is set to a specific value?
I tried to use
validates_length_of :fieldname, :maximum => 100, :if =>
:otherfieldname == ''myvalue''
But doesn''t work
Thanks
Paolo
2006 Mar 10
2
validation null objects and objects with data
...;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 => 18, :message => "Maximum
18 characters and numbers combined"
seems like I can''t win here...because I can''t pass validation uniqueness
if it is empty ("") and I can''t pass validation length if it is NULL
Suggestions?
Cr...
2005 Jul 07
3
NameError Exception
...employee.rb
department.rb
category.rb
document.rb
==================
======employee.rb======
class Employee < ActiveRecord::Base
belongs_to :department
belongs_to :location
has_many :versions
has_and_belongs_to_many :roles
validates_associated :locations, :roles, :versions
validates_length_of :first, :within=>1..50
validates_length_of :last, :within=>1..50
validates_length_of :resp, :maximum => 3
validates_format_of :resp_before_type_cast, :with => /([0-9]+)/,
:message=>"Only numbers are allowed in this field."
validates_length_of :office, :within=>0....
2011 Feb 28
1
(2.3.5) removing validations
Today I tried to remove (actually overwrite) a validation from a model,
from within a plugin.
This was the original validation:
validates_length_of :login, :maximum => 30
This was the only code I could come up with to replace it:
def self.included(base)
base.class_eval do
@validate_callbacks.delete_if { |callback|
begin
# Sorry, only way to remove validation...
# Probably tightly coupled to AR 2.3.5...
2006 Mar 29
11
why belongs_to does not like validation?
This works :
class Recipe < ActiveRecord::Base
belongs_to :category
end
But (when I add validation) this does not work :
class Recipe < ActiveRecord::Base
belongs_to :category
validates_length_of :category, :within => 6..20
validates_uniqueness_of :category, :message => "already exists"
end
thank you
--
View this message in context: http://www.nabble.com/why-belongs_to-does-not-like-validation--t1360119.html#a3643911
Sent from the RubyOnRails Users forum at Nabble.com.
2006 Jan 25
11
Schemas and Migrations
Hello-
I''m new to the ruby-based schemas and migrations. As I''m looking over
examples and such online, I see that many of them don''t make use of
schema-enforced attributes. For example, instead of:
t.column "post_id", :integer, :default => 0, :null => false
They do:
t.column "post_id", :integer
So I''m wondering -- is this
2006 Dec 29
2
update_attributes fails: ReadOnlyRecord
...ject was updated'')
redirect_to :action => ''index''
return
else
flash[:warning] = _(''Could not update project'')
end
end
end
Model:
class Project < ActiveRecord::Base
belongs_to :client
has_many :tasks
validates_length_of :name, :within => 2..100
validates_length_of :url, :within => 2..100
validates_uniqueness_of :url, :scope => :client_id
--
Posted via http://www.ruby-forum.com/.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google...
2006 Feb 09
0
Validations with conditions (:if)
...orks (using Symbols doesn''t work because the
active column is set always to false, using Proc''s the User class has an
invalid syntax and using a method has the same problem as using a
Symbol).
Can you tell me what I''m doing wrong?
Here is the code:
Using a symbol:
validates_length_of :name, :in => 3..30, :if = :active
Using proc:
validates_length_of :name, :in => 3..30, :if = Proc.new { |user|
user.active == true }
Using a method:
validates_length_of :name, :in => 3..30, :if = is_state_active
self.def is_state_active
Proc.new { |user| user.active =...
2011 Apr 18
2
acts_as_commentable validations
...w.
I''ve set up acts_as_commentable in my Post model and it''s working great.
Problem is users are able to create a "blank" comment. I''ve added the
following validations in the comment.rb file generated by
acts_as_commentable to limit the comment length:
[code]
validates_length_of :comment, :minimum => 3, :too_short => "must be at
least {{count}} words.", :tokenizer => lambda {|str| str.scan(/\w+/) }
validates_length_of :comment, :maximum => 200, :too_long => "must be
shorter than {{count}} words. Make sure there are no links or
elements."...
2006 Jul 04
1
LoginGenerator Problem
...hange_password(pass)
update_attribute "password", self.class.sha1(pass)
end
protected
def self.sha1(pass)
Digest::SHA1.hexdigest(pass)
end
before_create :crypt_password
def crypt_password
write_attribute("password", self.class.sha1(password))
end
validates_length_of :login, :within => 3..40
validates_length_of :password, :within => 5..40
validates_presence_of :login, :password, :password_confirmation
validates_uniqueness_of :login, :on => :create
validates_confirmation_of :password, :on => :create
end
class UserController < ApplicationC...
2007 Mar 26
2
Strange Record not saved errors
I have a site with an acts_as_authenticated based login which has
started throwing up some strange errors. Until a few days ago
everything worked fine but all of a sudden ''RecordNotSaved'' errors are
popping up in my logs.
When I check the database, it looks like the record _is_ saved but I
think users get an error so I''m starting to see a lot of double/triple
entries