Rails pass params/arguments to ActiveRecord callback function

前端 未结 4 1364
庸人自扰
庸人自扰 2021-02-05 06:17

I have the snippet below in one of my AR models:

after_update :cache_bust

The cache_bust method in the model accepts a parameter (

4条回答
  •  野性不改
    2021-02-05 06:24

    Very easy to pass params from controller to callback, you can call name of params in model. Example:

    In controller:

    Quiz.create(name: 'abc')
    

    In model:

    before_create :valid_name?
    
    def valid_name?
      puts name
    end
    

提交回复
热议问题