Why am I getting “Unable to autoload constant” with Rails and grape?

风格不统一 提交于 2019-12-03 10:21:42

Try either

  • Moving your API code's files from app/api to app/api/api, or

  • Moving your API classes outside the API module (i.e. deleting all the module API lines and their corresponding end statements).

From Grape's documentation:

Place API files into app/api. Rails expects a subdirectory that matches the name of the Ruby module and a file name that matches the name of the class. In our example, the file name location and directory for Twitter::API should be app/api/twitter/api.rb.

Thus the correct location for your API::Root class would actually be app/api/api/root.rb.

With this change your code starts and works fine for me on Rails 4.0.2.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!