API を作成するための gem の grape というのを使っています。
http://qiita.com/techno-tanoC/items/1aabd698e8fd912c699f
こちらのサイトと全く同じようにしたのですがうまくいきません。curl でためしてみると
$ curl http://0.0.0.0:8080/api/piyo curl: (7) Failed to connect to 0.0.0.0 port 8080: Connection refused
rails s
とすると
Circular dependency detected while autoloading constant API (RuntimeError)
このエラーが出ます。どのようにいたらいいのでしょうか。
ruby
1#app/api/piyo/api.rb 2 3 4module Piyo 5 class API < Grape::API 6 7 format :json 8 9 resource :api do 10 11 desc "Return piyo." 12 get :piyo do 13 "piyo" #とりあえずテキトーなものを返す 14 end 15 16 desc "twice echo." 17 params do 18 requires :str, type: String, desc: "twice str" 19 end 20 get :twice do 21 params[:str] * 2 22 end 23 24 end 25 end 26end
#config/application.rb module Test class Application < Rails::Aplication config.paths.add File.join('app', 'api'), glob: File.join('**', '*.rb') config.autoload_paths += Dir[Rails.root.join('app', 'api', '*')] end end
# config/routes.rb Rails.application.routes.draw do mount Piyo::API => '/' end
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。