Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialFrancisco Rodriguez
Courses Plus Student 2,703 PointsWhen I execute the command "Adding Todo items" I get this error undefined method `todolist_todoitems_path'
Hello There,
In the Generate s Scaffold I create the structure with the name todolist.
bin/rails generate scaffold todolist title:string description:text
In the class Relationships I generate the model for todoitem
bin/rails generate model todoitem todolist:references content:string
In the class view Todo Items
bin/rails generate controller todoitem index
The following files were added
file spec/model/todoitem_spce.rb
require 'spec_helper'
describe Todoitem do it {should belong_to(:todolist)} end
file spec/model/todolist_spec.rb
require 'spec_helper'
describe Todolist do it {should have_many(:todoitem)} end
file app/model/todoitem.rb
class Todoitem < ActiveRecord::Base
belongs_to :todolist end
file app/model/todolist.rb
class Todolist < ActiveRecord::Base
has_many :todoitem validates :title, presence: true validates :title, length: {minimum: 4} validates :description, presence: true validates :description, length: {minimum: 6} end
file app/config/route.rb
resources :todolists do
resources :todoitem
end
file app/controller/todoitem_controller.rb
class TodoitemController < ApplicationController
def index
@todolist = Todolist.find(params[:todolist_id])
end
def new
@todolist = Todolist.find(params[:todolist_id])
@todoitem = @todolist.todoitem.new
end
end
file app/db/migrate/create_todoitem.rb
class CreateTodoitems < ActiveRecord::Migration
def change create_table :todoitems do |t| t.references :todolist, index: true, foreign_key: true t.string :content
t.timestamps null: false
end
end end
file app/views/todoitem/new.html.erb
<%= form_for [@todolist, @todoitem] do |form| %>
<%= form.label :content %>
<%= form.text_field :content %>
<%= form.submit "Save" %>
<% end %>
file app/db/migrate/create_todolist.rb
class CreateTodolists < ActiveRecord::Migration
def change create_table :todolists do |t| t.string :title t.text :description
t.timestamps null: false
end
end end
file spec/features/todoitem
require 'spec_helper'
describe "Adding todo items" do
let!(:todolist){Todolist.create(title: "Grocery list", description: "Groceries")}
def visit_todolist(list) visit "/todolists"
within "#todolist_#{list.id}" do
click_link "List Item"
end
end
it "is successful with valid content" do
visit_todolist(todolist)
click_link "New Todo Item"
fill_in "Content", with: "Milk"
click_button "Save"
expect(page).to have_content("Added todo list item")
within "ul.todoitem" do
expect(page).to have_content("Milk")
end
end
end
Adding Todo items When I excecute the command
bin/rspec --format=documentation spec/features/todoitem/create_spec.rb
I get this error
Failure/Error: click_link "New Todo Item"
ActionView::Template::Error:
undefined method `todolist_todoitems_path' for #<#<Class:0x0000000ad6b9b0>:0x0000000b03a8d0>
# ./app/views/todoitem/new.html.erb:1:in `_app_views_todoitem_new_html_erb__1143243503_92391820'
Francisco Rodriguez
Courses Plus Student 2,703 PointsHello Justin,
Yes I already try that, and also I added the letter s to the other files and this did not work either
1 Answer
Vinny Harris-Riviello
11,898 Pointson your routes.rb you have:
resources :todolists do resources :todoitem
it should be:
resources :todolists do resources :todoitems
Marie Nipper
22,638 PointsMarie Nipper
22,638 PointsHave you tried adding the letter s to :todoitem route to make :todoitems?