没有路线匹配{:action =>“show”,}缺少必需的键:[:id]

时间:2015-10-18 23:18:54

标签: ruby-on-rails

尝试访问/学生时收到此错误消息:

No route matches {:action=>"show", :controller=>"students", :id=>nil} missing required keys: [:id]

有错误的文件是app / views / students / _student.haml

%tr
%td= student.first_name
%td= student.last_name
%td
= link_to student_path(student), { title: t('shared.show') } do
  %button.btn.btn-default
    = fa_icon "search"

型号:

class Student < ActiveRecord::Base
has_many :participations, dependent: :destroy
has_many :subject_item_notes, dependent: :destroy
validates :first_name, :last_name, presence: true
end

行动:(我也有更新和销毁行动)

class StudentsController < ApplicationController
expose(:student, attributes: :student_params)
expose(:student_subject_items) { student.subject_items }

def create
if student.save
redirect_to student_path(student), notice: I18n.t('shared.created', resource: 'Student')
else
render :new
end
end

路由

Rails.application.routes.draw do
devise_for :users
resources :students do
get :subjects end
resources :teachers do
get :subjects end
resources :reports do
get :subjects end
resources :visitors
resources :subject_items
root to:  'students#index' end

我的路线(演出行动的路线)是否有问题,或者我需要采取其他措施?我的其他控制器工作,我猜它几乎相同。这个错误是因为将学生#index设置为根路径吗?

index.html.haml

= link_to t('shared.add_new_item'), new_student_path, class: 'btn btn-default'
%table.table.table-condensed
%thead
%tr
%th= t('student.columns.first_name')
%th= t('student.columns.last_name')
%th= t('shared.actions')
%tbody
= render student

0 个答案:

没有答案