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

Were Teoh
Were Teoh
184 Points

NameError (uninitialized constant User::Authenticate):

I received this error NameError (uninitialized constant User::Authenticate), can teach me how to fix it?

ApiController:

module Api class ApiController < ApplicationController skip_before_filter :verify_authenticity_token protect_from_forgery with: :null_session before_filter :authenticate def authenticate authenticate_or_request_with_http_basic do |email, password| Rails.logger.info "API Authentication:#{email} #{password}" user = User.find_by(email: email) if(user && user.authenticate(password)) Rails.logger.info "Logging in #{user.inspect}" true else Rails.logger.warn "Invalid credentials" false end end end end end

Api Model:

class User < ActiveRecord::Base end

Error detail:

Started GET "/api/todo_lists/1/" for ::1 at 2016-05-08 16:46:14 +0800 Processing by Api::TodoListsController#show as JSON Parameters: {"id"=>"1", "todo_list"=>{}} API Authentication:test.com test1231 User Load (0.1ms) SELECT "users".* FROM "users" WHERE "users"."email" = ? LIMIT 1 [["email", "test.com"]] Completed 500 Internal Server Error in 4ms (ActiveRecord: 0.1ms)

NameError (uninitialized constant User::Authenticate): app/controllers/api/api_controller.rb:17:in block in authenticate' app/controllers/api/api_controller.rb:14:inauthenticate'

Hi Were. Can you correct the formatting of the code on your question? Just put three backticks before and after each code block.

For example:

```
my code
```