Skip to main content
Ask A Question
You’re not receiving notifications from this thread.

Can anyone see the error here?

Rails • Asked by Alan Morley

NameError in RecipesController#new

uninitialized constant RecipesController::Category

def new

@recipe =

@categories ={ |c| [,] } <-- saying this lines wrong


def create

Hey Alan,

What exactly is the error message?

Also, you should be able to accomplish the same thing using pluck which is more performant, you also don't have to use `all` for this:

@categories = Category.pluck(:name, :id)

Look like it can't find the `Category` model. Did you check to make sure there isn't any misspelling  in the `Category` model name?

uninitialized constant RecipesController::Category

Sorry, I didn't see that line before

As Toan said, check the spelling and file names for your category model. You should have a file in the models directory called category.rb (all lowercase) with class Category < ApplicationRecord (rails 5+) or class Category < ActiveRecord::Base if <= Rails 4

Login or Create An Account to join the conversation.

Subscribe to the newsletter

Join 29,763+ developers who get early access to new screencasts, articles, guides, updates, and more.

    By clicking this button, you agree to the GoRails Terms of Service and Privacy Policy.

    More of a social being? We're also on Twitter and YouTube.