2

私はRails 3.2でRuby 1.9.3を初めて使用し、個人的なプロジェクトに取り組んでいます。これは非常に基本的な複数選択トリビア ゲームであり、質問と question_choices をランダムに表示する「再生」リンクをユーザーがクリックできるように、コントローラーとビューにコードを書くのに問題があります。次に、ユーザーは、4 つの question_choices の 1 つに対応する 4 つのラジオ ボタンの 1 つを選択する必要があります。質問と question_choice が user_answers テーブルに追加され、次の質問が表示されます。また、ユーザーに同じ質問を 2 回表示させたくありません。

ここに私のモデルがあります:

class User < ActiveRecord::Base
  attr_accessible :name, :email, :password, :password_confirmation

  has_many :questions
  has_many :question_choices
  has_many :user_answers, dependent: :destroy
end

class Question < ActiveRecord::Base
    attr_accessible :level, :question, :is_active

    has_many :user_answers, through: :question_choices
    has_many :question_choices, dependent: :destroy
end

class QuestionChoice < ActiveRecord::Base
  attr_accessible :choice, :is_correct, :question_id

  has_many :user_answers, dependent: :destroy
  belongs_to :question
end

class UserAnswer < ActiveRecord::Base
  attr_accessible :answer_time, :user_id, :question_choice_id, :question_id

  belongs_to :user
  belongs_to :question
  belongs_to :question_choice
end

私のルート:

Trivia::Application.routes.draw do

  root to: 'static_pages#home'

  resources :sessions, only: [:new, :create, :destroy]  

  resources :questions do
    resources :question_choices
  end

  resources :users
  resources :user_answers
end

I've been able to use the scaffolding for 'index', 'new', 'edit' & 'show' for each separately but I'm having a tough time tying it together so the User can see a question and the question choices then select one and their UserAnswers gets updated.

Any help would be greatly appreciated.

Thank you. Shane

4

1 に答える 1