0

I'm testing the Grap API framework with Rails 4.1, but I'm stuck on this circlar dependency. Any idea why I get it?

app/api/v1/user.rb

module V1
  class User < Grape::API
    format :json
    desc 'Returns pong.'
    get :user do
      { ping: params[:pong] || 'pong' }
    end
  end
end

app/api/api.rb

class API < Grape::API
  prefix 'api'
  mount V1::User
end

app/models/user.rb

class User < ActiveRecord::Base
  [cut...]
martins
  • 9,669
  • 11
  • 57
  • 85
  • The circular dependency error goes away when I uncomment *config.autoload_paths += Dir["#{Rails.root}/app/api/*"]* from application.rb. But, then my tests fails: **No route matches [GET] "/api/v1/users"** – martins Jun 19 '14 at 08:29
  • What `require` statements do you have at the top of app/api/api.rb and app/api/v1/user.rb? –  Jun 19 '14 at 09:04
  • @SimonSouth, none. I'm trying to follow the pattern from https://github.com/dblock/grape-on-rails/blob/master/app/api/ – martins Jun 19 '14 at 10:17
  • I've pasted your code into a new Rails 4.1 project and fetching `/api/user` works fine for me. I suggest you search Stack Overflow for "circular dependency detected while autoloading constant" and read some of the answers here—apparently this error can crop up if you've upgraded to a new version of Rails or if you've accidentally duplicated code in multiple files. Or, if this is all the code you've written so far, you might consider simply starting over with a fresh Rails project. –  Jun 20 '14 at 15:27

0 Answers0