0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

activemodel callback

Last updated at Posted at 2016-06-24

class Pet
	extend ActiveModel::Callbacks

  define_model_callbacks :test

  before_test :motherfucker

  after_test do
  	puts "after that"
  end

  around_test do
  	puts 'around that'
  end

  def lala
  	puts "just a test"
  	# _run_test_callbacks do
  	# 	puts "real work"
  	# end

  	run_callbacks :test do
  		puts "real work"
  	end

  	
  	run_callbacks :test do
  		puts "real work"
  	end
  end

  def motherfucker
  	puts "before that"
  end
end

Pet.new.lala
class Pet
    extend ActiveModel::Callbacks

  define_model_callbacks :test

  before_test :motherfucker

  after_test do
    puts "after that"
  end

  around_test do
    puts 'around that'
  end

  skip_callback :test, :before, :motherfucker

  def lala
    puts "just a test"
    # _run_test_callbacks do
    #   puts "real work"
    # end

    run_callbacks :test do
        puts "real work"
    end


    run_callbacks :test do
        puts "real work"
    end
  end

  def motherfucker
    puts "before that"
  end
end

Pet.new.lala

但是好像skip_callback不能用于proc block
http://stackoverflow.com/questions/19021465/skip-before-filter-defined-with-block

0
0
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?