표준을 가르치기 위해 다양한 표준 및 질문에서 사용자가 수업을 만들 수있는 응용 프로그램을 구축하고 있지만 올바르게 설정했는지 정확하게 알 수는 없습니다. 아닙니다.여러 개의 레일 has_many : 연결을 통해 표시 및 연결
'새'페이지는 사용자가 표준이 선택되면, 사용자가 '편집'로 재 레슨 컨트롤러
def new
@search = Standard.search(params[:q])
@standards = @search.result
@lesson = Lesson.new
end
def create
@lesson = current_user.selects.build(params[:lesson])
if @lesson.save
redirect_to edit_lesson_path(@lesson)
else
render :action => 'new'
end
end
def edit
@lesson = Lesson.find(params[:id])
@standards = @lesson.standards
end
을 통해 표준을 선택을 통해 정렬 드롭 다운 메뉴를 사용할 수 있습니다 각 표준을 보여주는 페이지, 그러나 이것은 내가 문제가있는 부분이고 내 모델이 올바르게 설정되었는지 확신 할 수 없습니다. 표준을 선택하는 수업과 표준 사이에는 has_many through 관계가 있으며, 각 표준과 관련된 질문을 선택하기 위해 수업과 질문 사이에 has_many through 관계가 있습니다.
상위 표준 아래의 표준과 관련된 각 질문을 나열하려고하는데 '편집'메서드에서 @questions = @ standards.questions를 시도했지만 ActiveRecord 관계 NoMethod 오류가 호출되었습니다. 또한 @questions = Question.where (: standard_id => @standards)를 컨트롤러에서 시도했지만 페이지에는 각 표준의 모든 선택된 표준에 대한 모든 질문이 나열되어 있습니다.
내 수업 모델 :class Lesson < ActiveRecord::Base
attr_accessible :user_id, :name, :grade_id, :text_id, :date, :subject_id, :question_ids
has_many :select_standards
has_many :standards, through: :select_standards
has_many :select_questions
has_many :questions, through: :select_questions
end
표준 모델 :
class Standard < ActiveRecord::Base
attr_accessible :content, :grade_id, :subject_id
belongs_to :subject
belongs_to :grade
has_many :questions
end
질문 모델 :
class Question < ActiveRecord::Base
attr_accessible :content, :standard_id
belongs_to :standard
has_many :select_questions
has_many :lessons, through: :select_questions
end
Select_standards :
class Selection < ActiveRecord::Base
attr_accessible :lesson_id, :standard_id
belongs_to :lesson
belongs_to :standard
end
'select_standards'란 무엇입니까? 모델 정의를 게시 할 수도 있습니까? – vee
Select_standards는 사용자 선택을 보관하는 수업과 표준 사이의 조인 모델입니다. 그러나 나는 내 문제를 해결했다고 생각한다! 내 질문 모델에 "delegate : lesson, : to => : standard, : allow_nil => true"를 추가 했으므로 이제는 @ lesson.questions를 호출 할 수 있습니다. 도와 줘서 고마워. :) –