0

존재하지 않으며 내 모델관계는 내가 간단한 모듈이 ActiveSupport :: 우려

module Inputable 
    extend ActiveSupport::Concern 

    included do 
    has_many :inputs, as: :inputable, dependent: :destroy 
    end 
end 

class Product < ActiveRecord::Base 
    include Inputable 
end 

에 포함하지만 Product.first.inputs를 호출 할 때 내가

PG::UndefinedTable: ERROR: relation "inputs" does not exist 
LINE 5: WHERE a.attrelid = '"inputs"'::regclass          
: SELECT a.attname, format_type(a.atttypid, a.atttypmod) 

Product.reflect_on_all_associations.map { |assoc| assoc.name} 
=>[:inputs] 

무엇이 잘못 오류를 가지고있다 내 암호로?

+0

입력 모델을 생성하고'rake db : migrate'를 실행 했습니까? 어리석은 질문이지만, 내가 물어볼 줄 알았다. – jvillian

+0

너희 맞아, 내가하지 않았다. – user

+0

입력 이주 코드와 입력 모델을 보여줄 수 있습니까? –

답변

0

Input 모델을 생성하고 이전을 실행했는지 확인하십시오. 나는 included 후크를 사용하는 경우

또한, 그것은 더 같이하는 경향이있다 :

module Inputable 
    extend ActiveSupport::Concern 

    self.included(base) 
    base.class_eval do 
     has_many :inputs, as: :inputable, dependent: :destroy 
    end 
    end 

end 

내가 구문 당신을 위해 작품을 사용하고 있는지 알고 싶네. 행복한 metaprogramming!

+1

ActiveSupport :: Concern의 전체적인 아이디어는 이러한 'self.included (base)'접근법을 제거 (또는 숨겨서)하고 더 읽기 쉽게 만들어주는 것입니다 : http://api.rubyonrails.org/classes/ActiveSupport/Concern.html –

+0

@SebastianvomMeer - 링크 주셔서 감사합니다! 나는 내가 우려를 피하는 사람들 중 하나라고 생각한다. 따라서 나는 통사론에 익숙하지 않았다. 다시 포인터에게 감사드립니다. – jvillian