【发布时间】:2017-08-05 14:01:55
【问题描述】:
我在 Heroku 日志中收到此路由错误,我不确定如何修复它。我按照seen here 的说明进行操作。
这是我的 routes.rb 文件:
Rails.application.routes.draw do
resources :people, except: [:show]
root to: "people#index"
end
控制器people_controller.rb:
class PeopleController < ApplicationController
def index
@people = Person.all
end
def new
@person = Person.new
end
def create
@person = Person.new(person_params)
if @person.save
redirect_to people_path, notice: "The person has been created!" and return
end
render 'new'
end
def edit
@person = Person.find(params[:id])
end
def update
@person = Person.find(params[:id])
if @person.update_attributes(person_params)
redirect_to people_path, notice: "#{@person.first_name} #{@person.last_name} has been updated!" and return
end
render 'edit'
end
def destroy
@person = Person.find(params[:id])
@person.destroy
redirect_to people_path, notice: "#{@person.first_name} #{@person.last_name} has been deleted!" and return
end
private
def person_params
params.require(:person).permit(:first_name, :last_name, :email, :notes)
end
end
如果需要,这里是 person.rb 模型:
class Person
include Mongoid::Document
field :first_name, type: String
field :last_name, type: String
field :email, type: String
field :notes, type: String
end
【问题讨论】:
-
文件名是什么? Rails 要求文件名与类名匹配。
-
文件名为people_controller.rb,模型为person.rb。
-
请从您的日志文件中发布包含此路由错误的摘录。
-
它在本地工作吗?
标签: ruby-on-rails ruby routing ruby-on-rails-5