SubmittedQuizzes中的NoMethodError #index,为什么?

时间:2016-06-27 00:53:12

标签: ruby-on-rails

路线:

  resources :users do 
    resources :submitted_quizzes,   only: [:index, :create, :show] 
  end

submitted_quizzes / index.html.erb:

    <% @submitted_quizzes.each do |quiz| %>
            <ul>                    
                <li> <%= quiz.name %> <span><%= link_to 'Show', quiz %></span></li>
            </ul>           
    <% end %> 

submitted_quizzes / show.html.erb:

<%= @submitted_quiz.name %>  

SubmittedQuizzesController

def index
    @user = current_user
    @submitted_quizzes = @user.submitted_quizzes

    end

def show 
        @submitted_quiz = current_user.submitted_quizzes.find(params[:id])

    end

为什么会这样?

submitted_quiz.rb

class SubmittedQuiz < ActiveRecord::Base
  belongs_to :user
  belongs_to :quiz

  has_many :submitted_answers, :dependent => :destroy

  accepts_nested_attributes_for :submitted_answers, :reject_if => -> (a) {a[:content].blank? }, :allow_destroy => true
end

1 个答案:

答案 0 :(得分:1)

刚刚没有读过嵌套资源路径。正确的路径应该是user_submitted_quiz_path(@user, submitted_quiz)