Gem 使用 grape,出现`<module:APIEntities>': uninitialized constant Grape::Entity (NameError)

stephen · 2012年11月21日 · 最后由 EiraJeremy 回复于 2024年01月18日 · 4377 次阅读

这个写法有错?

module GuPiao
  module APIEntities
    class User < Grape::Entity
      expose :_id, :name, :login, :location
    end

    class Topic < Grape::Entity
    end
  end
end
/Users/stephen/gupiao/lib/api/entities.rb:3:in `<module:APIEntities>': uninitialized constant Grape::Entity (NameError)
    from /Users/stephen/gupiao/lib/api/entities.rb:2:in `<module:GuPiao>'
    from /Users/stephen/gupiao/lib/api/entities.rb:1:in `<top (required)>'
    from /Users/stephen/gupiao/lib/api.rb:1:in `<top (required)>'
    from /Users/stephen/gupiao/config/routes.rb:2:in `block in <top (required)>'
    from /Users/stephen/.rvm/gems/ruby-1.9.3-p125/gems/actionpack-3.2.7/lib/action_dispatch/routing/route_set.rb:282:in `instance_exec'
    from /Users/stephen/.rvm/gems/ruby-1.9.3-p125/gems/actionpack-3.2.7/lib/action_dispatch/routing/route_set.rb:282:in `eval_block'
    from /Users/stephen/.rvm/gems/ruby-1.9.3-p125/gems/actionpack-3.2.7/lib/action_dispatch/routing/route_set.rb:260:in `draw'
    from /Users/stephen/gupiao/config/routes.rb:1:in `<top (required)>'
    from /Users/stephen/.rvm/gems/ruby-1.9.3-p125/gems/railties-3.2.7/lib/rails/application/routes_reloader.rb:40:in `block in load_paths'
    from /Users/stephen/.rvm/gems/ruby-1.9.3-p125/gems/railties-3.2.7/lib/rails/application/routes_reloader.rb:40:in `each'
    from /Users/stephen/.rvm/gems/ruby-1.9.3-p125/gems/railties-3.2.7/lib/rails/application/routes_reloader.rb:40:in `load_paths'
    from /Users/stephen/.rvm/gems/ruby-1.9.3-p125/gems/railties-3.2.7/lib/rails/application/routes_reloader.rb:16:in `reload!'
    from /Users/stephen/.rvm/gems/ruby-1.9.3-p125/gems/railties-3.2.7/lib/rails/application/routes_reloader.rb:26:in `block in updater'
    from /Users/stephen/.rvm/gems/ruby-1.9.3-p125/gems/activesupport-3.2.7/lib/active_support/file_update_checker.rb:78:in `call'
    from /Users/stephen/.rvm/gems/ruby-1.9.3-p125/gems/activesupport-3.2.7/lib/active_support/file_update_checker.rb:78:in `execute'
    from /Users/stephen/.rvm/gems/ruby-1.9.3-p125/gems/railties-3.2.7/lib/rails/application/routes_reloader.rb:27:in `updater'
    from /Users/stephen/.rvm/gems/ruby-1.9.3-p125/gems/railties-3.2.7/lib/rails/application/routes_reloader.rb:7:in `execute_if_updated'
    from /Users/stephen/.rvm/gems/ruby-1.9.3-p125/gems/railties-3.2.7/lib/rails/application/finisher.rb:66:in `block in <module:Finisher>'
    from /Users/stephen/.rvm/gems/ruby-1.9.3-p125/gems/railties-3.2.7/lib/rails/initializable.rb:30:in `instance_exec'
    from /Users/stephen/.rvm/gems/ruby-1.9.3-p125/gems/railties-3.2.7/lib/rails/initializable.rb:30:in `run'
    from /Users/stephen/.rvm/gems/ruby-1.9.3-p125/gems/railties-3.2.7/lib/rails/initializable.rb:55:in `block in run_initializers'
    from /Users/stephen/.rvm/gems/ruby-1.9.3-p125/gems/railties-3.2.7/lib/rails/initializable.rb:54:in `each'
    from /Users/stephen/.rvm/gems/ruby-1.9.3-p125/gems/railties-3.2.7/lib/rails/initializable.rb:54:in `run_initializers'
    from /Users/stephen/.rvm/gems/ruby-1.9.3-p125/gems/railties-3.2.7/lib/rails/application.rb:136:in `initialize!'
    from /Users/stephen/.rvm/gems/ruby-1.9.3-p125/gems/railties-3.2.7/lib/rails/railtie/configurable.rb:30:in `method_missing'
    from /Users/stephen/gupiao/config/environment.rb:5:in `<top (required)>'
    from /Users/stephen/gupiao/config.ru:4:in `block in <main>'
    from /Users/stephen/.rvm/gems/ruby-1.9.3-p125/gems/rack-1.4.1/lib/rack/builder.rb:51:in `instance_eval'
    from /Users/stephen/.rvm/gems/ruby-1.9.3-p125/gems/rack-1.4.1/lib/rack/builder.rb:51:in `initialize'
    from /Users/stephen/gupiao/config.ru:1:in `new'
    from /Users/stephen/gupiao/config.ru:1:in `<main>'
    from /Users/stephen/.rvm/gems/ruby-1.9.3-p125/gems/rack-1.4.1/lib/rack/builder.rb:40:in `eval'
    from /Users/stephen/.rvm/gems/ruby-1.9.3-p125/gems/rack-1.4.1/lib/rack/builder.rb:40:in `parse_file'
    from /Users/stephen/.rvm/gems/ruby-1.9.3-p125/gems/rack-1.4.1/lib/rack/server.rb:200:in `app'
    from /Users/stephen/.rvm/gems/ruby-1.9.3-p125/gems/railties-3.2.7/lib/rails/commands/server.rb:46:in `app'
    from /Users/stephen/.rvm/gems/ruby-1.9.3-p125/gems/rack-1.4.1/lib/rack/server.rb:301:in `wrapped_app'
    from /Users/stephen/.rvm/gems/ruby-1.9.3-p125/gems/rack-1.4.1/lib/rack/server.rb:252:in `start'
    from /Users/stephen/.rvm/gems/ruby-1.9.3-p125/gems/railties-3.2.7/lib/rails/commands/server.rb:70:in `start'
    from /Users/stephen/.rvm/gems/ruby-1.9.3-p125/gems/railties-3.2.7/lib/rails/commands.rb:55:in `block in <top (required)>'
    from /Users/stephen/.rvm/gems/ruby-1.9.3-p125/gems/railties-3.2.7/lib/rails/commands.rb:50:in `tap'
    from /Users/stephen/.rvm/gems/ruby-1.9.3-p125/gems/railties-3.2.7/lib/rails/commands.rb:50:in `<top (required)>'
    from script/rails:6:in `require'
    from script/rails:6:in `<main>'
helpers APIHelpers

这句也报错,说参数错误,1 for 0

你没有 reuire 'grape'吧

@chenge 新版需要吗?我的版本和 ruby-china 一样,但是 ruby-china 好像也没有这一句!

@my location The error indicates that the class "Grape::Entity" has not been initialized. This could be due to a problem with the Grape gem or its configuration. Make sure the Grape gem is properly installed and configured in your project. Also check if the "Grape::Entity" class is defined in the Grape gem and is accessible in your project

需要 登录 后方可回复, 如果你还没有账号请 注册新账号