cannot load such file — lib/api grape in rails 3.2.3

494 views
Skip to first unread message

Maria Serrano Cáceres

unread,
Jul 3, 2012, 6:09:24 AM7/3/12
to ruby-...@googlegroups.com
I am trying run grape gem in my rails 3.2.3 app.

I'm following this tutorial:

http://martinciu.com/2011/01/mounting-grape-api-inside-rails-application.html

but I get this error:

    cannot load such file -- lib/api

I have added the config.autoload_paths += %W(#{config.root}/lib) in my application.rb file.

Also I have added require "lib/api" to my routes.rb file

**What's missing?**

Daniel Doubrovkine

unread,
Jul 3, 2012, 8:44:25 AM7/3/12
to ruby-...@googlegroups.com
In rails you shouldn't need to do the 'require' in routes.rb if the location of your api.rb is in the autoload_paths. If you place api.rb into lib, it should "just work" since lib is already autoloaded in Rails. What error(s) are you getting withotu any require or autoload_paths changes?

Maria Serrano Cáceres

unread,
Jul 3, 2012, 8:56:42 AM7/3/12
to ruby-...@googlegroups.com
If I remove the require "lib/api" from routes.rb I get this error:

uninitialized constant MyApp

Thank you!

Daniel Doubrovkine

unread,
Jul 3, 2012, 10:02:55 AM7/3/12
to ruby-...@googlegroups.com
Is lib/api a folder or lib/api.rb file? The file names and the class names should match in ruby, so if you have MyApp, it should be in my_app.rb and it should be on the load path.

Maria Serrano Cáceres

unread,
Jul 3, 2012, 10:29:51 AM7/3/12
to ruby-...@googlegroups.com
Thank you. This was the problem. The module name should match in ruby with the file names. The problem was fixed for me :D.

In the tutorial http://martinciu.com/2011/01/mounting-grape-api-inside-rails-application.html appear:

#lib/api.rb

this term leads to confusion and is incorrect.

Thank you!
Reply all
Reply to author
Forward
0 new messages