ActiveRecord::RecordNotFound in StudentsController#new 找不到 'id'=all 的学生



我刚开始使用ruby尝试创建联机表单它开始显示上述错误有人能帮我做这个吗我的代码students_controller.rb

 class StudentsController < ApplicationController
 def new
@student = Student.new
@students = Student.find(:all)
end
def create
@student = Student.new(student_params)
if @student.save
    redirect_to new_student_path
end
end
def student_params
allow = [:firstname, :lastname]
params.require(:student).permit(allow)
end
end

我的new.html 代码

Enter new student information 
<hr>
<%= form_for @student do |f| -%>
 Firstname: <%= f.text_field :firstname %><br /><br />
 Lastname:  <%= f.text_field :lastname %><br /><br />
<%= f.submit %>
<% end -%>
<hr>
Display all students' information
<% if !@students.blank? %>
<% for item in @students %>
   <%= item.firstname %> <%= item.lastname %> <br />
<% end %>
<% else %>
<% end %>

我的路线

Rails.application.routes.draw do
resources :students

使用

@students = Student.all

而不是

@students = Student.find(:all)

最新更新