whitesiroi
whitesiroi

Reputation: 2853

NoMethodError: undefined method ` validate' (custom validate) RAILS 3

my item.rb

# encoding: utf-8
class Item < ActiveRecord::Base
  attr_accessible :asin, :domain, :formatted_price, :user_id

  validate :double_dates

private

  def double_dates
    if Item.where(:user_id => self.user_id, :asin => self.asin, :domain => self.domain).where("DATE(created_at) = ?", Date.today).length == 1
      errors.add(:created_at, "no double dates")
    end
  end

end

Error message:

    from script/rails:6:in `<main>'irb(main):028:0> Item.new
NoMethodError: undefined method `  validate' for #<Class:0x007fb054ce7690>
    from .rvm/gems/ruby-1.9.3-p327/gems/activerecord-3.2.13/lib/active_record/dynamic_matchers.rb:55:in `method_missing'
...

Upvotes: 2

Views: 3046

Answers (1)

apneadiving
apneadiving

Reputation: 115541

Since it answered, lets post a real answer:

` validate' looked weird, a special character before the v must be removed.

Upvotes: 3

Related Questions