vendredi 2 septembre 2016

No route matches [GET] "/students/new"

I'm trying to create a basic form using ROR. I met this problem when running my rails code. I tried so many solutions from the internet but still couldn't fix this problem. I think the problem is in the routes.db file. Can you guys help me? and care to explain how routing works & when I need to write something in route.db? I'm a newbie to rails btw. and I'm using RubyMine IDE. Appreciate for any helps!

This is my new.html.erb

<h1>SignUp</h1>
<hr>
<%= form_for @student do |f| -%>
Firstname: <%= f.text_field :firstname %><br>
Lastname: <%= f.text_field :lastname %>
<%= f.submit %>
<%end -%>

This is my students.controller.rb

class StudentsController < ApplicationController
  def index
  end

  def new
@student = Student.new
  end

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

  end

This is my routes.rb

Rails.application.routes.draw do
 get 'students#index'
resources: Student

 end

Aucun commentaire:

Enregistrer un commentaire