Displaying 2 results from an estimated 2 matches for "add_on_blank".
2007 Aug 09
0
TypeError: $_ value need to be String (nil given)
...) Error:
test_pattern_splits(PatternSplitTest):
TypeError: $_ value need to be String (nil given)
/usr/lib/ruby/gems/1.8/gems/activerecord-1.15.2/lib/active_record/
validations.rb:74:in `split''
/usr/lib/ruby/gems/1.8/gems/activerecord-1.15.2/lib/active_record/
validations.rb:74:in `add_on_blank''
/usr/lib/ruby/gems/1.8/gems/activerecord-1.15.2/lib/active_record/
validations.rb:73:in `add_on_blank''
/usr/lib/ruby/gems/1.8/gems/activerecord-1.15.2/lib/active_record/
validations.rb:409:in `validates_presence_of''
/usr/lib/ruby/gems/1.8/gems/activerecord-1....
2006 Feb 09
3
accessing associated models in a validate method
Why can''t I access an associated model in a validate method? I have
some code that looks like the following:
Models:
class Product < ActiveRecord::Base
has_many: upcs
end
class Upc < ActiveRecord::Base
belongs_to :product
def validate
errors.add_on_blank(''upc'') unless product.new_record?
end
end
Controller:
def create
@product = Product.new(params[:product])
@upc = Upc.new(params[:upc])
@product.upcs << @upc unless @upc.upc.empty?
if @product.save
# ...
end
end
When the create method gets called I g...