jkfairless
jkfairless

Reputation: 41

Inscrutable Error

I am getting this error in my sinatra app:

NameError at / uninitialized constant Category file: app.rb location: block in <top (required)> line: 8

app.rb

get('/') do
  @recipes = Recipe.all
  @categories = Category.all
  erb(:index)
end

index.erb

<% if @categories.any?() %>
    <% @categories.each() do |category| %>
        <ul>
            <li><a href='/category/<%=category.id()%>'> <%=category.cat_name()%></a></li>
        </ul>
    <%end%>
<%else %>
  <p> You have no categories!</p>
<%end%>

It fails at: @categories = Category.all in app.rb

It also fails with the same error in rspec:

require('spec_helper')
describe(Category) do

    it('creates a new category') do
        category = Catergory.create({:cat_name => 'italian'})
        expect(category.cat_name()).to(eq(category.cat_name))
    end
end

Category.rb

class Category < ActiveRecord::Base
  has_many(:recipes)
end

Recipe.rb

class Recipe < ActiveRecord::Base
  has_many(:ingredients)
  has_many(:instructions)
  has_many(:images)
  belongs_to(:category)
end

Upvotes: 0

Views: 41

Answers (1)

pdoherty926
pdoherty926

Reputation: 10349

There's a typo in your test.

Change Catergory to Category in:

category = Catergory.create({:cat_name => 'italian'})

Upvotes: 2

Related Questions