Ruby on rails 未定义的方法`学生路径';对于#<#&书信电报;类别:0x00000003b7a860>;:0x00000003b6d6d8>;你是说?学生径

Ruby on rails 未定义的方法`学生路径';对于#<#&书信电报;类别:0x00000003b7a860>;:0x00000003b6d6d8>;你是说?学生径,ruby-on-rails,Ruby On Rails,我有一段时间会遇到这个错误 my student_controller.rb文件: class StudentController < ApplicationController def new @student=Student.new end def create @student=Student.new(params[:student]) if @student.save redirect_to new_student_path end e

我有一段时间会遇到这个错误 my student_controller.rb文件:

class StudentController < ApplicationController

def new
@student=Student.new
end

def create 
    @student=Student.new(params[:student])
    if @student.save
        redirect_to new_student_path
    end
end 
end

尝试在
students\u controller.rb
中重命名控制器。注意学生是复数的

还可以从以下位置重命名类名:

class StudentController < ApplicationController

不是使用
而是尝试使用
它无法共享您的路由。rb文件是否重新启动了Web服务器?是的,我重新启动了它,出现了一个新错误:无法使用
@student=student自动编辑您的创建操作。新建(:firstname,:lastname)
该页面现在可接收,但新错误:参数数量错误(给定2,预期为0..1)我添加了一个代码示例,可用于重构创建操作..请告诉我是否有效:)
Rails.application.routes.draw do
resources :student
end
class StudentController < ApplicationController
class StudentsController < ApplicationController
def create
  @student = Student.new(student_params)

  if @student.save
    redirect_to new_student_path
  end

end

  private
  # Never trust parameters from the scary internet, only allow the white list through.
  def student_params
    params.require(:student).permit(:firstname, :lastname)
  end
<%= form_for Student.new do |f| %>
<%= form_for Student.new, url: student_index_path do |f| %>