[英]How to draw routes in Rails engine gem?
I'm having a lot of trouble drawing routes in an engine gem I'm building. 在我正在构建的引擎gem中绘制路径时遇到了很多麻烦。 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: /app/controllers/rails_dribbble_oauth/main_controller.rb:
module RailsDribbbleOauth
class MainController < ::ApplicationController
# some instance methods
end
end
/lib/rails_dribbble_oauth/engine.rb: /lib/rails_dribbble_oauth/engine.rb:
module RailsDribbbleOauth
class Engine < ::Rails::Engine
isolate_namespace :RailsDribbbleOauth
end
end
lib/rails_dribbble_oauth.rb: LIB / rails_dribbble_oauth.rb:
require "rails_dribbble_oauth/engine"
module RailsDribbbleOauth
end
config/routes.rb: 配置/ 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. 当我将它添加到我的测试应用程序并运行rake路由时,gem中定义的所有路径都不会出现在我的应用程序中。
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
. 我也尝试使用
RailsDribbbleOauth::Engine.routes.draw
安装它,然后mount RailsDribbbleOauth::Engine, at: '/dribbble'
我的测试应用程序中添加mount RailsDribbbleOauth::Engine, at: '/dribbble'
,然后将其导入NameError: uninitialized constant RailsDribbbleOauth::Engine
。
Any help is really appreciated, thank you. 非常感谢任何帮助,谢谢。
Edit: test app's Gemfile does include the gem. 编辑:测试应用程序的Gemfile确实包含了gem。 Gem is currently being developed within the test app at
lib/engines/rails_dribbble_oauth
. Gem目前正在
lib/engines/rails_dribbble_oauth
的测试应用程序中开发。 From test app's Gemfile: gem 'rails-dribbble-oauth', path: 'lib/engines/rails_dribbble_oauth'
. 从测试应用程序的Gemfile:gem'rail
gem 'rails-dribbble-oauth', path: 'lib/engines/rails_dribbble_oauth'
。 Still, rake routes
does not yield any routes defined in the gem. 不过,
rake routes
不会产生宝石中定义的任何路线。
Maybe you need to add the engine to the test applications Gemfile
, for example: 也许您需要将引擎添加到测试应用程序
Gemfile
,例如:
# 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'
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.