新建的api文件 app/api/api.rb
http://gist.github.com/c6eb81aeebe4fa347b3b在routes.rb中添加
mount JokesApi::API => "/"
修改application.rb
添加gem gem ‘grape’
rails s 启动服务器报错,信息如下:
=> Booting WEBrick
=> Rails 4.0.0.rc1 application starting in development on
http://0.0.0.0:3000=> Run `rails server -h` for more startup options
=> Ctrl-C to shutdown server
Exiting
/Users/sjwu/Desktop/joke_app/config/routes.rb:5:in `block in <top (required)>': uninitialized constant JokesApi (NameError)
from /Users/sjwu/.rbenv/versions/2.0.0-p195/lib/ruby/gems/2.0.0/gems/actionpack-4.0.0.rc1/lib/action_dispatch/routing/route_set.rb:315:in `instance_exec'
from /Users/sjwu/.rbenv/versions/2.0.0-p195/lib/ruby/gems/2.0.0/gems/actionpack-4.0.0.rc1/lib/action_dispatch/routing/route_set.rb:315:in `eval_block'
from /Users/sjwu/.rbenv/versions/2.0.0-p195/lib/ruby/gems/2.0.0/gems/actionpack-4.0.0.rc1/lib/action_dispatch/routing/route_set.rb:293:in `draw'
from /Users/sjwu/Desktop/joke_app/config/routes.rb:2:in `<top (required)>'
from /Users/sjwu/.rbenv/versions/2.0.0-p195/lib/ruby/gems/2.0.0/gems/railties-4.0.0.rc1/lib/rails/application/routes_reloader.rb:40:in `block in load_paths'
from /Users/sjwu/.rbenv/versions/2.0.0-p195/lib/ruby/gems/2.0.0/gems/railties-4.0.0.rc1/lib/rails/application/routes_reloader.rb:40:in `each'
from /Users/sjwu/.rbenv/versions/2.0.0-p195/lib/ruby/gems/2.0.0/gems/railties-4.0.0.rc1/lib/rails/application/routes_reloader.rb:40:in `load_paths'
from /Users/sjwu/.rbenv/versions/2.0.0-p195/lib/ruby/gems/2.0.0/gems/railties-4.0.0.rc1/lib/rails/application/routes_reloader.rb:16:in `reload!'
from /Users/sjwu/.rbenv/versions/2.0.0-p195/lib/ruby/gems/2.0.0/gems/railties-4.0.0.rc1/lib/rails/application/routes_reloader.rb:26:in `block in updater'
from /Users/sjwu/.rbenv/versions/2.0.0-p195/lib/ruby/gems/2.0.0/gems/activesupport-4.0.0.rc1/lib/active_support/file_update_checker.rb:75:in `call'
from /Users/sjwu/.rbenv/versions/2.0.0-p195/lib/ruby/gems/2.0.0/gems/activesupport-4.0.0.rc1/lib/active_support/file_update_checker.rb:75:in `execute'
from /Users/sjwu/.rbenv/versions/2.0.0-p195/lib/ruby/gems/2.0.0/gems/railties-4.0.0.rc1/lib/rails/application/routes_reloader.rb:27:in `updater'
from /Users/sjwu/.rbenv/versions/2.0.0-p195/lib/ruby/gems/2.0.0/gems/railties-4.0.0.rc1/lib/rails/application/routes_reloader.rb:6:in `execute_if_updated'
from /Users/sjwu/.rbenv/versions/2.0.0-p195/lib/ruby/gems/2.0.0/gems/railties-4.0.0.rc1/lib/rails/application/finisher.rb:69:in `block in <module:Finisher>'
from /Users/sjwu/.rbenv/versions/2.0.0-p195/lib/ruby/gems/2.0.0/gems/railties-4.0.0.rc1/lib/rails/initializable.rb:30:in `instance_exec'
from /Users/sjwu/.rbenv/versions/2.0.0-p195/lib/ruby/gems/2.0.0/gems/railties-4.0.0.rc1/lib/rails/initializable.rb:30:in `run'
from /Users/sjwu/.rbenv/versions/2.0.0-p195/lib/ruby/gems/2.0.0/gems/railties-4.0.0.rc1/lib/rails/initializable.rb:55:in `block in run_initializers'
from /Users/sjwu/.rbenv/versions/2.0.0-p195/lib/ruby/2.0.0/tsort.rb:150:in `block in tsort_each'
from /Users/sjwu/.rbenv/versions/2.0.0-p195/lib/ruby/2.0.0/tsort.rb:183:in `block (2 levels) in each_strongly_connected_component'
from /Users/sjwu/.rbenv/versions/2.0.0-p195/lib/ruby/2.0.0/tsort.rb:219:in `each_strongly_connected_component_from'
from /Users/sjwu/.rbenv/versions/2.0.0-p195/lib/ruby/2.0.0/tsort.rb:182:in `block in each_strongly_connected_component'
from /Users/sjwu/.rbenv/versions/2.0.0-p195/lib/ruby/2.0.0/tsort.rb:180:in `each'
from /Users/sjwu/.rbenv/versions/2.0.0-p195/lib/ruby/2.0.0/tsort.rb:180:in `each_strongly_connected_component'
from /Users/sjwu/.rbenv/versions/2.0.0-p195/lib/ruby/2.0.0/tsort.rb:148:in `tsort_each'
from /Users/sjwu/.rbenv/versions/2.0.0-p195/lib/ruby/gems/2.0.0/gems/railties-4.0.0.rc1/lib/rails/initializable.rb:54:in `run_initializers'
from /Users/sjwu/.rbenv/versions/2.0.0-p195/lib/ruby/gems/2.0.0/gems/railties-4.0.0.rc1/lib/rails/application.rb:214:in `initialize!'
from /Users/sjwu/.rbenv/versions/2.0.0-p195/lib/ruby/gems/2.0.0/gems/railties-4.0.0.rc1/lib/rails/railtie/configurable.rb:30:in `method_missing'
from /Users/sjwu/Desktop/joke_app/config/environment.rb:5:in `<top (required)>'
from /Users/sjwu/.rbenv/versions/2.0.0-p195/lib/ruby/gems/2.0.0/gems/backports-3.3.3/lib/backports/tools.rb:328:in `require'
from /Users/sjwu/.rbenv/versions/2.0.0-p195/lib/ruby/gems/2.0.0/gems/backports-3.3.3/lib/backports/tools.rb:328:in `require_with_backports'
from /Users/sjwu/Desktop/joke_app/config.ru:3:in `block in <main>'
from /Users/sjwu/.rbenv/versions/2.0.0-p195/lib/ruby/gems/2.0.0/gems/rack-1.5.2/lib/rack/builder.rb:55:in `instance_eval'
from /Users/sjwu/.rbenv/versions/2.0.0-p195/lib/ruby/gems/2.0.0/gems/rack-1.5.2/lib/rack/builder.rb:55:in `initialize'
from /Users/sjwu/Desktop/joke_app/config.ru:in `new'
from /Users/sjwu/Desktop/joke_app/config.ru:in `<main>'
from /Users/sjwu/.rbenv/versions/2.0.0-p195/lib/ruby/gems/2.0.0/gems/rack-1.5.2/lib/rack/builder.rb:49:in `eval'
from /Users/sjwu/.rbenv/versions/2.0.0-p195/lib/ruby/gems/2.0.0/gems/rack-1.5.2/lib/rack/builder.rb:49:in `new_from_string'
from /Users/sjwu/.rbenv/versions/2.0.0-p195/lib/ruby/gems/2.0.0/gems/rack-1.5.2/lib/rack/builder.rb:40:in `parse_file'
from /Users/sjwu/.rbenv/versions/2.0.0-p195/lib/ruby/gems/2.0.0/gems/rack-1.5.2/lib/rack/server.rb:277:in `build_app_and_options_from_config'
from /Users/sjwu/.rbenv/versions/2.0.0-p195/lib/ruby/gems/2.0.0/gems/rack-1.5.2/lib/rack/server.rb:199:in `app'
from /Users/sjwu/.rbenv/versions/2.0.0-p195/lib/ruby/gems/2.0.0/gems/railties-4.0.0.rc1/lib/rails/commands/server.rb:48:in `app'
from /Users/sjwu/.rbenv/versions/2.0.0-p195/lib/ruby/gems/2.0.0/gems/rack-1.5.2/lib/rack/server.rb:314:in `wrapped_app'
from /Users/sjwu/.rbenv/versions/2.0.0-p195/lib/ruby/gems/2.0.0/gems/railties-4.0.0.rc1/lib/rails/commands/server.rb:75:in `start'
from /Users/sjwu/.rbenv/versions/2.0.0-p195/lib/ruby/gems/2.0.0/gems/railties-4.0.0.rc1/lib/rails/commands.rb:80:in `block in <top (required)>'
from /Users/sjwu/.rbenv/versions/2.0.0-p195/lib/ruby/gems/2.0.0/gems/railties-4.0.0.rc1/lib/rails/commands.rb:75:in `tap'
from /Users/sjwu/.rbenv/versions/2.0.0-p195/lib/ruby/gems/2.0.0/gems/railties-4.0.0.rc1/lib/rails/commands.rb:75:in `<top (required)>'
from bin/rails:4:in `require'
from bin/rails:4:in `<main>'
高手帮忙看下,是啥原因,新学rails不久,搞不明白,为什么JokeApi文件没有自己加载?
谢谢。。。