I'm having a lot of trouble drawing routes in an engine gem I'm building. No idea what I'm doing wrong...I must have tried a half dozen different things already. Currently my gem looks like this:
Gem structure:
├── Gemfile
├── MIT-LICENSE
├── README.md
├── app
│ └── controllers
│ └── rails_dribbble_oauth
│ └── main_controller.rb
├── config
│ └── routes.rb
├── lib
│ ├── rails_dribbble_oauth
│ │ ├── engine.rb
│ │ └── version.rb
│ └── rails_dribbble_oauth.rb
└── rails_dribbble_oauth.gemspec
/app/controllers/rails_dribbble_oauth/main_controller.rb:
module RailsDribbbleOauth
class MainController < ::ApplicationController
# some instance methods
end
end
/lib/rails_dribbble_oauth/engine.rb:
module RailsDribbbleOauth
class Engine < ::Rails::Engine
isolate_namespace :RailsDribbbleOauth
end
end
lib/rails_dribbble_oauth.rb:
require "rails_dribbble_oauth/engine"
module RailsDribbbleOauth
end
config/routes.rb:
Rails.application.routes.draw do
get 'request', to: 'main#request', as: "dribbble_oauth_request"
get 'callback', to: 'main#passthru', as: "dribbble_callback"
end
When I add this into my test app and run rake routes, none of the routes defined in the gem appear in my app.
I've also tried mounting it by using RailsDribbbleOauth::Engine.routes.draw
, then adding mount RailsDribbbleOauth::Engine, at: '/dribbble'
into my test app, but that's resulted in NameError: uninitialized constant RailsDribbbleOauth::Engine
.
Any help is really appreciated, thank you.
Edit: test app's Gemfile does include the gem. Gem is currently being developed within the test app at lib/engines/rails_dribbble_oauth
. From test app's Gemfile: gem 'rails-dribbble-oauth', path: 'lib/engines/rails_dribbble_oauth'
. Still, rake routes
does not yield any routes defined in the gem.
Maybe you need to add the engine to the test applications Gemfile
, for example:
# if the engines in at RAILS_ROOT/engines
gem 'rails_dribble_oauth', path: 'engines/rails_dribble_oauth'
# somewhere else
gem 'rails_dribble_oauth', path: '~/dev/rails_dribble_oauth'
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.