2
Rails 3.2.11 앱에서 Grape API를 실행하려고합니다. 포도 문서에 따르면 다음 줄을 내 config/application.rb에 추가해야합니다. 아래 코드Rails 3.2.11 & Grape에서는 다음 파일을 찾을 수 없습니다. app/api/v1.rb
# Auto-load API and its subdirectories
config.paths.add "app/api", :glob => "**/*.rb"
config.autoload_paths += Dir["#{Rails.root}/app/api/*"]
그리고 생성 설정/초기화/reload_api.rb :
if Rails.env.development?
api_files = Dir["#{Rails.root}/app/api/**/*.rb"]
api_reloader = ActiveSupport::FileUpdateChecker.new(api_files) do
Rails.application.reload_routes!
end
ActionDispatch::Callbacks.to_prepare do
api_reloader.execute_if_updated
end
end
하지만 나를 위해 작동하지 않습니다. 여기 내 코드가있다.
module Api
class V1 < Grape::API
get '/hello' do
[]
end
end
end
그리고 내 설정/routes.rb : 나는 rake routes
을 실행하면
Blog::Application.routes.draw do
mount Api::V1 => "/"
end
내가받을 다음과 같은 오류 : 내 응용 프로그램/API/v1.rb에서
uninitialized constant Api
/home/zoloo/code/nomin/config/routes.rb:7:in `block in <top (required)>'
/home/zoloo/.rvm/gems/[email protected]/gems/actionpack-3.2.11/lib/action_dispatch/routing/route_set.rb:282:in `instance_exec'
/home/zoloo/.rvm/gems/[email protected]/gems/actionpack-3.2.11/lib/action_dispatch/routing/route_set.rb:282:in `eval_block'
/home/zoloo/.rvm/gems/[email protected]/gems/actionpack-3.2.11/lib/action_dispatch/routing/route_set.rb:260:in `draw'
/home/zoloo/code/nomin/config/routes.rb:5:in `<top (required)>'
/home/zoloo/.rvm/gems/[email protected]/gems/railties-3.2.11/lib/rails/application/routes_reloader.rb:40:in `block in load_paths'
/home/zoloo/.rvm/gems/[email protected]/gems/railties-3.2.11/lib/rails/application/routes_reloader.rb:40:in `each'
/home/zoloo/.rvm/gems/[email protected]/gems/railties-3.2.11/lib/rails/application/routes_reloader.rb:40:in `load_paths'
/home/zoloo/.rvm/gems/[email protected]/gems/railties-3.2.11/lib/rails/application/routes_reloader.rb:16:in `reload!'
/home/zoloo/.rvm/gems/[email protected]/gems/railties-3.2.11/lib/rails/application/routes_reloader.rb:26:in `block in updater'
/home/zoloo/.rvm/gems/[email protected]/gems/activesupport-3.2.11/lib/active_support/file_update_checker.rb:78:in `call'
/home/zoloo/.rvm/gems/[email protected]/gems/activesupport-3.2.11/lib/active_support/file_update_checker.rb:78:in `execute'
/home/zoloo/.rvm/gems/[email protected]/gems/railties-3.2.11/lib/rails/application/routes_reloader.rb:27:in `updater'
/home/zoloo/.rvm/gems/[email protected]/gems/railties-3.2.11/lib/rails/application/routes_reloader.rb:7:in `execute_if_updated'
/home/zoloo/.rvm/gems/[email protected]/gems/railties-3.2.11/lib/rails/application/finisher.rb:66:in `block in <module:Finisher>'
/home/zoloo/.rvm/gems/[email protected]/gems/railties-3.2.11/lib/rails/initializable.rb:30:in `instance_exec'
/home/zoloo/.rvm/gems/[email protected]/gems/railties-3.2.11/lib/rails/initializable.rb:30:in `run'
/home/zoloo/.rvm/gems/[email protected]/gems/railties-3.2.11/lib/rails/initializable.rb:55:in `block in run_initializers'
/home/zoloo/.rvm/gems/[email protected]/gems/railties-3.2.11/lib/rails/initializable.rb:54:in `each'
/home/zoloo/.rvm/gems/[email protected]/gems/railties-3.2.11/lib/rails/initializable.rb:54:in `run_initializers'
/home/zoloo/.rvm/gems/[email protected]/gems/railties-3.2.11/lib/rails/application.rb:136:in `initialize!'
/home/zoloo/.rvm/gems/[email protected]/gems/railties-3.2.11/lib/rails/railtie/configurable.rb:30:in `method_missing'
/home/zoloo/code/nomin/config/environment.rb:5:in `<top (required)>'
/home/zoloo/.rvm/gems/[email protected]/gems/railties-3.2.11/lib/rails/application.rb:103:in `require'
/home/zoloo/.rvm/gems/[email protected]/gems/railties-3.2.11/lib/rails/application.rb:103:in `require_environment!'
/home/zoloo/.rvm/gems/[email protected]/gems/railties-3.2.11/lib/rails/application.rb:297:in `block (2 levels) in initialize_tasks'
Tasks: TOP => routes => environment
(See full trace by running task with --trace)
그것은 분명 예외는 Rails가 내 API를로드 할 수 없다고 말했습니다. 왜? 에
대단히 감사합니다. :). 작동 중입니다 ........ – Zeck