私はこのセットでいくつかのクラスを持っています:
class Campaign < ActiveRecord::Base
belongs_to :user
validates_presence_of :title, :description
def initialize
validates_format_of_many([:title, :description])
end
def validates_format_of_many(inputs)
if (!inputs.nil?)
inputs.each do |input|
validates_format_of input => /^[.]/, :allow_nil => false, :allow_blank => false
puts YAML::dump('test1')
end
else
puts YAML::dump('test2')
end
end
end
問題は、エラーメッセージundefined method
が含まれていることです。nil:NilClass`およびスタック内
/usr/lib/ruby/gems/1.8/gems/activerecord-2.3.14/lib/active_record/attribute_methods.rb:257:in `method_missing'
/var/www/gitorious/app/models/campaign.rb:13:in `validates_format_of_many'
/var/www/gitorious/app/models/campaign.rb:12:in `each'
/var/www/gitorious/app/models/campaign.rb:12:in `validates_format_of_many'
/var/www/gitorious/app/models/campaign.rb:7:in `initialize'
/var/www/gitorious/app/controllers/campaigns_controller.rb:28:in `new'
/var/www/gitorious/app/controllers/campaigns_controller.rb:28:in `new'