请帮帮我。我不确定我是否有路线问题或复数,但是这个错误发生了,不再知道该做什么,已经在很多地方研究过,什么都没有。
我开始设计一个迷你教程并且有效,登录工作正常。所以我想重用它并构建一个待办事项列表。
当我将部分渲染放到我希望他们留在字段中创建待办事项列表时,会发生:
ActionView::Template::Error (undefined method `model_name' for NilClass:Class):
1: <%= form_for(@todo_list) do |f| %>
2: <% if @todo_list.errors.any? %>
3: <div id="error_explanation">
4: <h2><%= pluralize(@todo_list.errors.count, "error") %> prohibited this todo_list from being saved:</h2>
路线:
match 'dashboard' => 'home#dashboard'
match 'register' =>'registration#register'
root :to => 'home#index'
new_member_session GET /members/sign_in(.:format) devise/sessions#new
member_session POST /members/sign_in(.:format) devise/sessions#create
destroy_member_session DELETE /members/sign_out(.:format) devise/sessions#destroy
member_password POST /members/password(.:format) devise/passwords#create
new_member_password GET /members/password/new(.:format) devise/passwords#new
edit_member_password GET /members/password/edit(.:format) devise/passwords#edit
PUT /members/password(.:format) devise/passwords#update
cancel_member_registration GET /members/cancel(.:format) registration#cancel
member_registration POST /members(.:format) registration#create
new_member_registration GET /members/sign_up(.:format) registration#new
edit_member_registration GET /members/edit(.:format) registration#edit
PUT /members(.:format) registration#update
DELETE /members(.:format) registration#destroy
dashboard /dashboard(.:format) home#dashboard
register /register(.:format) registration#register
root / home#index
型号:
class ToDoList < ActiveRecord::Base
attr_accessible :is_favorite, :name, :description
has_many :tasks, dependent: :destroy
belongs_to :member
控制器:
class ToDoListController < ApplicationController
def index
@todo_lists = ToDoList.all
respond_to do |format|
format.html # index.html.erb
format.json { render json: @todo_lists }
end
end
def new
@todo_list = ToDoList.new
respond_to do |format|
format.html # new.html.erb
format.json { render json: @todo_list }
end
end
答案 0 :(得分:-1)
尝试:
将Controller重命名为:
类ToDoListsController
也相应地更改文件名和目录名。