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

后端 未结 1 1708
太阳男子
太阳男子 2021-02-13 01:14

I want to do an API for an Android app. When searching, I found {grape}. I\'m following this tutorial, but I have a problem launching the Rails server:

=> Boo         


        
1条回答
  •  再見小時候
    2021-02-13 02:01

    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.

    0 讨论(0)
提交回复
热议问题