search for: validates_each

Displaying 20 results from an estimated 35 matches for "validates_each".

2006 Mar 31
10
ruby help / if (cond or cond)
Why this code doesn''t work as expected? It raises exceptions everytime. Tried with || operator, too. validates_each :x, :y do |record, attr| record.errors.add (attr, ''between 1 and 100'') if (attr.to_i>100 or attr.to_i<0) end -- They say money can''t buy happiness? Look at the smile on my face... ear to ear, baby!
2006 Feb 24
2
Shortcircuit evaluations
This is probably a Ruby questions but since my issue exists in a Rails validation I thought I''d post here. I have the following validator validates_each :thumbnail, :regular do |record, attribute, value| unless value.nil? && value.valid? record.errors.add( attribute, value.errors.full_messages[0]) end...
2005 May 04
1
Conditional validations
...ample, I have a 4-part sign-up process that must record as much data as possible after each step--it''s not good enough to keep it in the session and then store it all in one save at the end. The good news is that this modification to ActiveRecord::Validations would be very simple. In the validates_each method, I added the following line: if options[:if] and record.send(options[:if]) ... so that validates_each now looks like this: def validates_each(*attrs) options = attrs.last.is_a?(Hash) ? attrs.pop.symbolize_keys : {} attrs = attrs.flatten # Declare t...
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 Apr 28
2
validates* gives me problems
...cle:0x407f6418> RAILS_ROOT: /var/www/audio/public/../config/.. Application Trace | Framework Trace | Full Trace #{RAILS_ROOT}/vendor/rails/activerecord/lib/active_record/base.rb:1786:in `method_missing'' #{RAILS_ROOT}/vendor/rails/activerecord/lib/active_record/validations.rb:300:in `validates_each'' #{RAILS_ROOT}/vendor/rails/activerecord/lib/active_record/validations.rb:299:in `validates_each'' . . . Don''t know what i''m doing wrong Cheers, Antonio -- Posted via http://www.ruby-forum.com/.
2006 Jan 13
1
validating without saving
...d-1.13.2/lib/active_record/base.rb:1501:in `method_missing'' from /usr/local/lib/ruby/gems/1.8/gems/activerecord-1.13.2/lib/active_record/validations.rb:294:in `send'' from /usr/local/lib/ruby/gems/1.8/gems/activerecord-1.13.2/lib/active_record/validations.rb:294:in `validates_each'' from /usr/local/lib/ruby/gems/1.8/gems/activerecord-1.13.2/lib/active_record/validations.rb:293:in `each'' from /usr/local/lib/ruby/gems/1.8/gems/activerecord-1.13.2/lib/active_record/validations.rb:293:in `validates_each'' from /usr/local/lib/ruby/...
2006 May 04
2
validates* give me problems
...ria:0x40a606cc> RAILS_ROOT: /var/www/audio/public/../config/.. Application Trace | Framework Trace | Full Trace #{RAILS_ROOT}/vendor/rails/activerecord/lib/active_record/base.rb:1786:in `method_missing'' #{RAILS_ROOT}/vendor/rails/activerecord/lib/active_record/validations.rb:300:in `validates_each'' #{RAILS_ROOT}/vendor/rails/activerecord/lib/active_record/validations.rb:299:in `validates_each'' #{RAILS_ROOT}/vendor/rails/activerecord/lib/active_record/validations.rb:794:in `run_validations'' #{RAILS_ROOT}/vendor/rails/activerecord/lib/active_record/validations.rb:7...
2006 Aug 09
1
Migrating a Field to External Model
...race: wrong number of arguments (1 for 2) /usr/local/lib/ruby/gems/1.8/gems/rake-0.7.1/lib/rake.rb:812:in `link'' /usr/local/lib/ruby/gems/1.8/gems/rake-0.7.1/lib/rake.rb:812:in `link'' /usr/local/lib/ruby/gems/1.8/gems/activerecord-1.14.2/lib/ active_record/validations.rb:300:in `validates_each'' /usr/local/lib/ruby/gems/1.8/gems/activerecord-1.14.2/lib/ active_record/validations.rb:299:in `validates_each'' /usr/local/lib/ruby/gems/1.8/gems/activerecord-1.14.2/lib/ active_record/validations.rb:794:in `run_validations'' /usr/local/lib/ruby/gems/1.8/gems/activereco...
2007 Jul 24
4
Possible Bug
...:user_id => @user.id ) @book.should_receive( :store_with_privacy? ).with( @clip ) clipping = Clipping.new( valid_clipping_attributes.with( :clip => @clip, :book => @book ) ) clipping.valid? end And the model class Clipping < AR:B belongs_to :clip belongs_to :book ... validates_each :clip do |model, attr, value| if !model.book.nil? && !model.clip.nil? if !model.book.store_with_privacy?( model.clip ) model.errors.add( :clip, "You can''t add this item to this book" ) end end end ... end Any thoughts on what might be causi...
2006 May 16
2
Validate Before Delete
...is validate that the status of the Order is not completed before it is allowed to be deleted. I tried the following method in my Model, but it appears that this only works for an :update or :create on the record. Anyone know how to do this, and if it should be in the model or the controller? validates_each :approval_status do |record, attr, value| record.errors.add attr, ''Order Is Completed'' if value == "Completed" end -------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060516/...
2009 Jun 17
2
validates_uniqueness_of fails on STI in Rails 2.3.2
...2.3.2/lib/active_record/base.rb:2156:in `with_exclusive_scope'' from /home/joaz/.gem/ruby/1.8/gems/activerecord-2.3.2/lib/active_record/validations.rb:757:in `validates_uniqueness_of'' from /home/joaz/.gem/ruby/1.8/gems/activerecord-2.3.2/lib/active_record/validations.rb:399:in `validates_each'' from /home/joaz/.gem/ruby/1.8/gems/activerecord-2.3.2/lib/active_record/validations.rb:396:in `each'' from /home/joaz/.gem/ruby/1.8/gems/activerecord-2.3.2/lib/active_record/validations.rb:396:in `validates_each'' from /home/joaz/.gem/ruby/1.8/gems/activesupport-2.3....
2006 Jun 20
2
Problem with "can''t dump anonymous class Class"
.../gems/activerecord-1.14.2/lib/active_record/base.rb :380:in `find'' C:/Ruby/lib/ruby/gems/1.8/gems/activerecord-1.14.2/lib/active_record/validat ions.rb:528:in `validates_uniqueness_of'' C:/Ruby/lib/ruby/gems/1.8/gems/activerecord-1.14.2/lib/active_record/validat ions.rb:302:in `validates_each'' C:/Ruby/lib/ruby/gems/1.8/gems/activerecord-1.14.2/lib/active_record/validat ions.rb:299:in `validates_each'' C:/Ruby/lib/ruby/gems/1.8/gems/activerecord-1.14.2/lib/active_record/validat ions.rb:794:in `run_validations'' C:/Ruby/lib/ruby/gems/1.8/gems/activerecord-1....
2005 Sep 27
2
No Custom Validation
Hi, Correct me if I am wrong but there doesn''t seem to be an easy way to add validation outside the pre-built ones (validates_presence_of, validates_lenght_of, etc.). Ideally there should be something like: Class Person < ActiveRecord::Base validates :my_method, :on => create, :message => ''was not valid'' def my_method(param) false unless
2006 Dec 11
2
Custom Validator
I want to add a custom validator in one of Model. For example Rails has inbuilt validation methods like validates_uniqueness_of, validates_presence_of . What I need is a similar kind of method (example: validates_line_items), that can run my custom code while saving, updating the record and can add custom error messages to the record. Please help me by suggesting how i can do this. -- Posted via
2009 Nov 13
3
Encoding::UTF_8 missing?
...vesupport-2.3.4/lib/active_support/core_ext/string/multibyte.rb:44:in `mb_chars'' /Library/Ruby/Gems/1.8/gems/activerecord-2.3.4/lib/active_record/validations.rb:798:in `validates_uniqueness_of'' /Library/Ruby/Gems/1.8/gems/activerecord-2.3.4/lib/active_record/validations.rb:468:in `validates_each'' /Library/Ruby/Gems/1.8/gems/activerecord-2.3.4/lib/active_record/validations.rb:465:in `each'' /Library/Ruby/Gems/1.8/gems/activerecord-2.3.4/lib/active_record/validations.rb:465:in `validates_each'' /Library/Ruby/Gems/1.8/gems/activesupport-2.3.4/lib/active_support/callba...
2005 Dec 16
4
Validation with Aggregation
ActiveRecord supports composed_of for value objects which is fantastic but one thing that it doesn''t seem to support (or at least I am unable to find any documentation for) validation of the value objects. For example, given the following: class Message < ActiveRecord::Base composed_of :sender, :class_name => ''EmailAddress'' composed_of :recipient,
2006 Jul 02
2
NoMethodError in Unit Test - Rails Newcomer
I''m working on user authentication system to get familiar with rails, and have basically solved most of my apps problems till now. I keep getting the NoMethodError, and can''t understand why. Model: customer.rb class Customer < ActiveRecord::Base ... def self.password=(pass) @password=pass salt = Customer.random_string(10) if !salt? self.hashed_password =
2009 Mar 05
7
issue with the object cache
Hi, I am getting a method_missing error when I run my application in the production environment unless I set config.cache_classes = false in config/environments/production.rb. This happens in Rails 2.2.2 but not in Rails 2.1.0. The method that is missing is one I used to have before I edited by hand the migration that creates the table associated with the object (I know you are discouraged to do
2006 Jun 19
3
can''t dump anonymous class Class
I''m trying to create a document upload system, where most of the code is the super class Document and just the path to file on the system is controlled by the sub classes. When I attempt to use my code, I get the following when I try to save the document. can''t dump anonymous class Class Any ideas? ** Migration ** class CreateDocuments < ActiveRecord::Migration def
2006 Mar 16
5
TimeZone, TZInfo, daylight savings, and composed_of
Does anyone know the best way to track time zone information. There doesn''t seem to be much documentation on this. So far it seems like a simple db field like create table accounts ( id int unsigned not null auto_increment, name varchar(50) not null, time_zone varchar(50) not null, ... primary key (id) ) and a class like class Account < AR ...