ruby-grape / grape

An opinionated framework for creating REST-like APIs in Ruby.
http://www.ruby-grape.org
MIT License
9.89k stars 1.22k forks source link

Mounted in Rails routes, 404 #2069

Closed jahio closed 4 years ago

jahio commented 4 years ago

I've got a very simple API I'm trying to build mounted inside an otherwise empty Rails 6 app. The code is in app/api/name/api.rb for just a small part of the app, but the bulk of the code presently lives in other files. I do not want to mix my entire app's code into one giant file. How can I get this Grape app working, inside Rails, and not have all my stuff in one several-thousand line Ruby file?

A screenshot of the directory structure and existing code:

Screen Shot 2020-06-07 at 8 55 08 AM

Note that this exact same Grape code itself did work in a previous version of this app I had built without Rails. I ran into some very unusual Rails-specific crap when using ActiveRecord and decided, "screw it, I'll just go full Rails for this" to get around it, and I copied over the code verbatim following the directions, but now I'm running into this oddity.

I've also tried having all three files in the app/api directory next to each other; only api.rb gets picked up. If I explicitly require_relative './users.rb' or something like that I get a complaint from Zeitwork about expecting the files to be named a certain way which is why I organized them by directory and class inheritance as seen in the screenshot.

Related: How can I also see my Grape-defined/specific routes inside this Rails app? rake routes doesn't exactly help here, just showing that the Grape app is mounted at /.

dm1try commented 4 years ago

I've got a very simple API I'm trying to build mounted inside an otherwise empty Rails 6 app. The code is in app/api/name/api.rb for just a small part of the app, but the bulk of the code presently lives in other files. I do not want to mix my entire app's code into one giant file. How can I get this Grape app working, inside Rails, and not have all my stuff in one several-thousand line Ruby file?

see https://github.com/ruby-grape/grape#modules

Related: How can I also see my Grape-defined/specific routes inside this Rails app? rake routes doesn't exactly help here, just showing that the Grape app is mounted at /.

https://github.com/ruby-grape/grape#describing-and-inspecting-an-api and there was a couple of gems for integration with rails, try to use search

dblock commented 4 years ago

Related: How can I also see my Grape-defined/specific routes inside this Rails app? rake routes doesn't exactly help here, just showing that the Grape app is mounted at /.

https://github.com/ruby-grape/grape#describing-and-inspecting-an-api and there was a couple of gems for integration with rails, try to use search

https://github.com/syedmusamah/grape_on_rails_routes