내 모델에서 after_find를 사용하고 있지만 경우에 따라 사용을 중지하고 싶습니다. 그리고 난 을 사용하고 있습니다. 여전히 after_find가 실행 중이지만 문서에서는 다음과 같은 방법으로 만 작동한다고합니다. 왜 그래야만하지?일부 경우에만 after_find를 사용 중지하는 방법이 있습니까
all
first
find
find_by
find_by_*
find_by_*!
find_by_sql
last
내 API (포도 프레임 워크)를 after_find
콜백이 where
호출에 의해 호출되지 않는
delete '/delete_user' do
user_id = params[:user_id] #authenticate_current_user!
@user_profile = ::UserProfile.where(user_id: user_id).
@user_profile.destroy_all
end
정보를 얻은 문서는 어느 것입니까? [rails documentation] (http://api.rubyonrails.org/classes/ActiveRecord/Callbacks.html)은 다음과 같이 말합니다 : "파인더에 의해 발견되고 인스턴스화 된 각 객체에 대해'after_find' 및'after_initialize' 콜백이 트리거됩니다 "*. 그리고'find_by_ *'메소드는 v4 이후에 코어 레일에서 더 이상 사용되지 않거나 제거되었으며 레일 5에서 완전히 제거되었습니다. –
코드를 보여 주시겠습니까? "어떤 경우에는 사용 중지"란 무엇을 의미합니까? 'after_find'를 전혀 포함하지 않는 문제에 대한 더 깔끔한 해결책이있을 수 있습니다. –
http://guides.rubyonrails.org/active_record_callbacks.html에서 확인하십시오. 코드도 추가했습니다. –