ruby on rails - undefined method `students_path' for #<#<Class:0x00000003b7a860>:0x00000003b6d6d8> Did you mean? student_path -


i getting error while student_controller.rb file:

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 

and new.html.erb file:

 student infos  <%= form_for student.new |f| %>  firstname:<%= f.text_field :firstname %> <br/>  lastname:<%= f.text_field :lastname %> <br>  <%= f.submit %>  <% end %> 

the student_controller.rb file located in controller folder , new.html.erb file located in /views/student/ ruby version 2.3.0p0 , rails version 5.0.0 please , routes.rb file:

rails.application.routes.draw resources :student end 

try rename controller in students_controller.rb. note students plural.

also rename class name from:

class studentcontroller < applicationcontroller 

to:

class studentscontroller < applicationcontroller 

edit

you can write create action follow:

def create   @student = student.new(student_params)    if @student.save     redirect_to new_student_path   end  end    private   # never trust parameters scary internet, allow white list through.   def student_params     params.require(:student).permit(:firstname, :lastname)   end 

Comments