0
레일 - 앱에는 두 가지 모델이 있습니다. 요소 및 타입으로 전화를 걸자. :elements has_and_belongs_to_many :types
내가 몇 가지 유형을 제외 할 요소 모델에서 이제 :types has_and_belongs_to_many :elements
레일 : before_filter 요소를 제외하려면
는 같은 매끄러운 :
class Element < ActiveRecord::Base
before_filter :exclude_some_types
def exclude_some_types
# if certain type satisfies condition, exclude it from the types list
end
내가 어떻게 코딩 할 수 있습니다? 나는 제외 부분을 의미합니다.
THX
'before_filter'는 컨트롤러 용입니다. 나는 당신이'before_save'를 사용하기를 원한다고 생각합니다. http://guides.rubyonrails.org/active_record_validations_callbacks.html#callbacks-overview – Baldrick
을 참조하십시오. 당신이 당신의 관계를 설정하기 위해 사용하고있는 어떤 형식에서든 그 유형을 제외시키고 자 할 것 같습니다. 그렇게하기 위해서는 뷰에서 도우미 메서드 만 사용하면됩니다. –