难以理解的错误

时间:2015-10-01 01:46:47

标签: ruby sinatra

我在我的sinatra应用程序中收到此错误:

if(is_page(199) || $post->post_parent == '199') {
dynamic_sidebar( 'widget-area' );
}

app.rb

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

index.erb

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

它失败了:app.rb中的<% 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%>

它在rspec中也出现了同样的错误:

@categories = Category.all

Category.rb

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

Recipe.rb

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

1 个答案:

答案 0 :(得分:2)

你的考试中有一个错字。

Catergory更改为Category

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