설명하기가 어렵지만 최선을 다할 것입니다 :컨트롤러 설계 (레일 3)
사용자가 코스를 수강 할 수있는 시스템을 구축 중입니다. 과정은 단계별로 이루어지며 순서대로 수행해야합니다. 시스템에서 6 단계 종류가 있습니다 (다운로드, 프리젠 테이션, 비디오, 텍스트, 퀴즈 및 설문 조사) 사용자가 현재 단계에 액세스
방법은 다음과 같습니다
http://example.com/courses/2/course_steps/1
당신이 course_steps을 말할 수 코스 아래에 중첩되어 있습니다. 다음은
코스 단계 쇼 방법 :def show
render "show_#{@course_step.step.step_type.name.downcase}"
end
당신은 기본적으로 [TYPE] (퀴즈, 설문 조사, text..etc)
이 작품을 show_ 할 뷰를 선택합니다 말할 수 텍스트, 비디오 또는 다운로드와 같은 간단한 단계는 괜찮지 만 다음과 같은 이유로 퀴즈와 같은 복잡한 단계에서는이 모델이 제대로 작동하지 않습니다.
- 퀴즈 또는 설문 조사는 내가 될거야 다른 컨트롤러 (QuizAttemptsController)를 부릅니다.
- REST 교장을 퀴즈로 여는 것처럼 보입니다. 설문 조사는 별도로 처리해야합니다. (나는 그들이 단계 유형을 알고 있지만, 그들은 자신의 행동과 검증 할 수 있습니다)
단계 모델
class Step < ActiveRecord::Base
belongs_to :step_type
belongs_to :client
has_one :step_quiz, :dependent => :destroy
has_one :step_survey, :dependent => :destroy
has_one :step_text, :dependent => :destroy
has_one :step_download, :dependent => :destroy
has_one :step_video, :dependent => :destroy
has_one :step_presentation, :dependent => :destroy
has_many :course_steps, :dependent => :destroy
has_many :courses, :through => :course_steps
has_many :patient_course_steps, :dependent => :destroy
attr_accessible :step_type_id, :client_id, :title, :subtitle, :summary
validates :title, :presence=>true
validates :summary, :presence=>true
def getSpecificStepObject()
case self.step_type.name.downcase
when "text"
return StepText.find_by_step_id(self.id)
when "quiz"
return StepQuiz.find_by_step_id(self.id)
when "survey"
return StepSurvey.find_by_step_id(self.id)
when "download"
return StepDownload.find_by_step_id(self.id)
when "video"
return StepVideo.find_by_step_id(self.id)
when "presentation"
return StepPresentation.find_by_step_id(self.id)
end
end
end
단계 퀴즈 모델 :
class StepQuiz < ActiveRecord::Base
belongs_to :step, :dependent => :destroy
has_many :step_quiz_questions, :dependent => :destroy
has_many :quiz_attempts, :dependent => :destroy
accepts_nested_attributes_for :step
accepts_nested_attributes_for :step_quiz_questions, :allow_destroy => true
attr_accessible :step_id, :instructions, :step_attributes, :step_quiz_questions_attributes
validates :instructions, :presence=>true
end
CourseStep을 모델
class CourseStep < ActiveRecord::Base
belongs_to :step
belongs_to :course
validates_uniqueness_of :step_id, :scope => :course_id
def next_step()
Course.find(self.course.id).course_steps.order(:position).where("position >= ?", self.position).limit(1).offset(1).first
end
def previous_step()
Course.find(self.course.id).course_steps.order("position DESC").where("position <= ?", self.position).limit(1).offset(1).first
end
end
어떻게 수정 하시겠습니까? 당신이 원하는 무엇