所以我真的是新的鐵路和看了幾個教程後,我決定去做一個基本的網站。我目前正處於開發階段,但有一個障礙,我似乎無法得到link_to
,因爲我在加載頁面時收到No route matches
錯誤。Rails - 在路由中的new_projects_path,但得到'沒有路由匹配'的錯誤
這是我的索引頁代碼
<h1>Projects#index</h1>
<%= link_to "Create new project", action: new_project_path %>
我碰到我的終端new_project_path
當我輸入命令rake routes
這裏是返回的一切:
Prefix Verb URI Pattern Controller#Action
root GET / projects#index
projects GET /projects(.:format) projects#index
POST /projects(.:format) projects#create
new_project GET /projects/new(.:format) projects#new
edit_project GET /projects/:id/edit(.:format) projects#edit
project GET /projects/:id(.:format) projects#show
PATCH /projects/:id(.:format) projects#update
PUT /projects/:id(.:format) projects#update
DELETE /projects/:id(.:format) projects#destroy
和這裏來自projects_controller
文件的代碼:
class ProjectsController < ApplicationController
def index
end
def create
@project = Project.create(project_params)
if(@project.save)
redirect_to root_url, :notice => "Project added"
else
render "new"
end
end
def new
@project = Project.new
end
private
def project_params
params.require(:project).permit(:title, :desc, :dates)
end
end
我只是想知道我哪裏出錯了,因爲這已經困擾了幾個小時了。任何幫助,你可以給予不勝感激! :) 我檢查了文檔,似乎無法找到我的錯誤,所以我真的不知道。
這就是它!謝謝:)對不起,這是一個簡單的修復! –