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 trial

Ruby User Authentication with Rails Password Hashing and Sign In Creating the Sessions Controller

Gísli Guðmundsson
Gísli Guðmundsson
2,640 Points

I have an issue, I have done these 0DOT project but in this particular video I get an error when doing POST 'create'

This is my config in the user_sessions_controller_spec.rb

user_sessions_controller_spec.rb
    it "redirects to the todo list path" do
      post :create, email: "jason@teamtreehouse.com", password: "treehouse1"
      expect(response).to be_redirect
      expect(response).to redirected_to(todo_list_path)
    end

The error I get is

1) UserSessionsController POST 'create' redirects to the todo list path
     Failure/Error: post :create, email: "jason@teamtreehouse.com", password: "treehouse1"
     ActionController::UrlGenerationError:
       No route matches {:controller=>"todo_lists", :action=>"show"} missing required keys: [:id]
     # ./app/controllers/user_sessions_controller.rb:6:in `create'
     # ./spec/controllers/user_sessions_controller_spec.rb:19:in `block (3 levels) in <top (required)>'

It seems like it does not find todo_list action show.

Any ideas ?

3 Answers

Gísli Guðmundsson
Gísli Guðmundsson
2,640 Points

Ahh figured it out, the user_sessions_controller.rb had missing s (plural) todo_list_path

class UserSessionsController < ApplicationController

def new

end

def create

redirect_to todo_lists_path

end

end

Maciej Czuchnowski
Maciej Czuchnowski
36,441 Points

This:

expect(response).to redirected_to(todo_list_path)

1) It should say redirect_to, not redirected,

2) todo_list should be plural, so (todo_lists_path) - todo_list in singular requires an id of the list you want

This assumes that all your controller and form code is correct.

Gísli Guðmundsson
Gísli Guðmundsson
2,640 Points

Tried

expect(response).to redirect_to(todo_list_path)

expect(response).to redirect_to(todo_lists_path)

now I set it to

  expect(response).to be_redirect

  expect(response).to redirect_to(todo_lists_path)

But still I get

Failure/Error: post :create, email: "jason@teamtreehouse.com", password: "treehouse1" ActionController::UrlGenerationError: No route matches {:controller=>"todo_lists", :action=>"show"} missing required keys: [:id]

I am not sure where the required key id is ?