연관은 has_and_belongs_to_many
이며 보석으로 정의됩니다. 나는 새로운 것을 추가 할 때 이것을 알고 싶다. 대답을 말할 수있는 것은 after_add
callback이지만, 사실 후에 어떻게 추가 할지를 알 수 없다. 지금이모델 데코레이터의 루비 연결에`after_add` 콜백을 추가 할 수 있습니까?
코드는 작동하지 않습니다 :
(보석으로)
job.rb
module Spree
class Job < Spree::Base
has_and_belongs_to_many :users, join_table: 'spree_jobs_users', class_name: Spree.user_class.to_s
end
end
(내 고장 코드)
job_decorator.rb
을Spree::Job.class_eval do
has_and_belongs_to_many :users, join_table: 'spree_jobs_users',
class_name: Spree.user_class.to_s, after_add: :test
def test
# after method
end
end
이 방법이 효과가 있습니까? 아니면 새로운 일자리가 언제 추가되는지 알아내는 다른 방법?