Alan Coromano
Alan Coromano

Reputation: 26008

Before_save methods are not called

My model:

class MyModel < ActiveRecord::Base

  before_save [:method1!, :method2!]
  #..........

  private

  def method1!
    puts 'method1'
  end

  def method2!
    puts 'method2'
  end
end

The methods method1 and method2 aren't not called for some reason when I save a model. Is there any error in my code?

Upvotes: 0

Views: 270

Answers (2)

Amit
Amit

Reputation: 224

Just modify the model

class MyModel < ActiveRecord::Base

  before_save :method1!, :method2!
  #..........

  private

  def method1!
    puts 'method1'
  end

  def method2!
    puts 'method2'
  end
end

I think it will help you.

Thanks.

Upvotes: 2

SR5
SR5

Reputation: 95

Try this: before_save do method1! end

private def method1! puts "method1!" end

Upvotes: 1

Related Questions