title: Defining custom methods within a model/class in Rails 4
body: <p>I have the following model:</p>
  
  <pre><code>class ActivityLog &lt; ActiveRecord::Base
    validates :user_id, :instance_id, :action, presence: true
    validates :user_id, :instance_id, :action, numericality: true
  
    def log
      ActivityLog.create(
        user_id: current_user ? current_user.id : -1,
        instance_id: instance_id,
        action: actions.index(action)
        )
    end
  
    private 
  
    def actions
      ['start','stop','create','destroy']
    end
  
  end
  </code></pre>
  
  <p>When I call the following line from the rails console, I get an error:</p>
  
  <pre><code>ActivityLog.log(user_id: 1, instance_id:1, action: 'create')
  
  # Error returned from console
  NoMethodError: undefined method `log' for #&lt;Class:0x007fb4755a26a8&gt;
  </code></pre>
  
  <p>Why doesn't my method call work? I defined it in the class, but it says it is undefined. What am I missing or misunderstanding? Thank you.</p>