2
Next, I received a challenge to create a page with login, using Sign in and with the user logged in, that he could create a task list, an to-do list.
The login I managed to do and works well, already create the part of the posts this being the biggest problem. created some files, the model, the controler, a partial and the view that should call this partial.
The insistent error is:
ActionView::Template::Error (undefined method `model_name' for NilClass:Class):
2: <%= form_for(@todo_list) do |f| %>
3: <% if @todo_list.errors.any? %>
4: <div id="error_explanation">
5: <h2><%= pluralize(@todo_list.errors.count, "error") %> prohibited this todo_list from being saved:</h2>
I already debugged, the @todo_list comes null, I do not know why, since apparently everything is well declared and instantiated.
Here’s the model:
class ToDoList < ActiveRecord::Base
attr_accessible :is_favorite, :name, :description
has_many :tasks, dependent: :destroy
belongs_to :member
end
the controller:
`class ToDoListsController < ApplicationController
def index
...
def show
...
end
def new
@todo_list = ToDoList.new
respond_to do |format|
format.html # new.html.erb
format.json { render json: @todo_list }
end`
the section of the view that calls the partial:
<% if member_signed_in? %>
<%= render partial: 'to_do_lists/to_do_list' %>
<%= link_to "Saída", destroy_member_session_path, :method => :delete %>
<% else %>
the routes:
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
Edit: One thing worked, but it’s not the idea...
<%= form_for(@todo_list = ToDoList.new) do |f| %>
<%#= form_for(@todo_list) do |f| %>
<% if @todo_list.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(@todo_list.errors.count, "error") %> prohibited this todo_list from being saved:</h2>
<ul>
<% @todo_list.errors.full_messages.each do |msg| %>
<li><%= msg %></li>
<% end %>
</ul>
</div>
<% end %>
Changing @todo_list to Todolist.new. It worked, but I can’t do it all the time ;/.
Edit2
Index function:
class ToDoListsController < ApplicationController
def index
@todo_lists = ToDoList.all
respond_to do |format|
format.html # index.html.erb
format.json { render json: @todo_lists }
end
end
end
What is the content of the index method of the class Todolistcontroller?
– Bernardo Botelho
As @Bernardo said, the error is in the action
index
and you just posted the code ofnew
– user7261
sorry guys, the code:
class ToDoListsController < ApplicationController

 def index
 @todo_lists = ToDoList.all

 respond_to do |format|
 format.html # index.html.erb
 format.json { render json: @todo_lists }
 end
 end
.– noob-rails