Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ruby/rails NoMethodError? when using custom validation method

i'v been new to ruby and rails and encountered a rather strange error:

class Person < ActiveRecord::Base
    validates_presence_of :description, :if => require_description_presence?

    def require_description_presence?
        self.can_send_email
    end
end

raises

NoMethodError in PeopleController#index

undefined method `require_description_presence?' for #<Class:0x4c4fadc> 
like image 929
lordlinier Avatar asked Feb 27 '23 18:02

lordlinier


1 Answers

You should pass validation method as symbol:

validates_presence_of :description, :if => :require_description_presence?
like image 187
Eimantas Avatar answered Mar 02 '23 07:03

Eimantas