Tag: rails engine

如何避免Devise从引擎内部进行身份validation?

我在我的主应用程序中使用Devise进行身份validation,并且我使用“http_basic_authenticate_with”构建了一个API(用于PABX),当我将before_action :authenticate_user!, except: [:method_name]到我的控制器时,它运行良好。 我这样做是因为except: [:method_name]不需要在Devise上记录用户会话,我只想对这些API控制器使用基本身份validation。 config/routes.rb (主应用程序) scope module: ‘api’ do scope module: ‘pabx’ do scope ‘/api/pabx’ do get ‘/accounts/phone_number/:phone_number’, to: ‘accounts#phone_number’ end end end controllers/api/pabx/accounts_controller.rb (主要应用) class Api::Pabx::AccountsController < ApplicationController http_basic_authenticate_with name: 'some_name', password: 'some_password' before_action :authenticate_user!, except: [:phone_number] skip_before_filter :verify_authenticity_token # POST api/pabx/accounts/phone_number.json def phone_number … end end 当我想在Engine中执行与API类似的操作时,问题就出现了。 当我尝试访问路由时,Devise似乎不允许在没有身份validation的情况下访问它,即使我正在使用before_action :authenticate_user!, except: […]

rails prepend_view_path可安装引擎

一方面,我有一个可安装的引擎让我们说Front Front包含我的资产和几页它与MainApp隔离。 我不希望它触及主应用程序。 另一方面,我希望我的MainApp使用布局和Front的部分。 所以我这样设置布局: class ApplicationController < ActionController::Base layout 'front/application' end 但是前端/应用程序直接引用引擎部分,因为隔离,就像这样 render ‘header’ # front/ prefix is not required 因此,MainApp视图尝试加载app / views / application / header而不是app / views / front / application / header 为了解决这个问题,我把prepend_view_path放到这样: class ApplicationController < ActionController::Base layout 'front/application' before_filter :prepend_front protected def prepend_front prepend_view_path "app/views/front" end end 但这不起作用,因为引擎路径指向供应商。 引擎将它自己添加到前置路径列表:〜/ main_app […]

Rails 3.0引擎 – 在ActionController中执行代码

我正在升级我的Rails插件,使其成为最新3.0RC1版本的引擎,并且我在找出扩展ActionController的最佳(也是最正确的)方法时遇到了一些麻烦。 我已经在DHH上看过这篇文章了, 这个问题在这里,但是我的问题更多的是关于如何在ActionController正确调用代码。 例如,我需要在我的引擎控制器中调用以下内容: class ApplicationController < ActionController::Base helper :all before_filter :require_one_user after_filter :store_location private def require_one_user # Code goes here end def store_location # Code goes here end end 我知道如何正确地包含我的两个私有函数,但我找不到一种方法来正确调用helper , before_filter和after_filter 。 我非常感谢一些链接或方法来使这项工作。 我已经尝试将我的控制器命名为ApplicationController其他东西,并让真正的ApplicationController扩展它,但这似乎也不起作用。 我真的很想找到能让发动机用户的生活变得尽可能简单的任何解决方案。 理想情况下,他们不必扩展我的类,但他们拥有内置于自己的ApplicationController所有function。

如何从主应用程序访问Rails引擎方法?

我正在尝试使用Spree :: Core引擎中定义的current_order方法: https : //github.com/spree/spree/blob/master/core/lib/spree/core/current_order.rb 在我看来,我已经尝试过了 Spree::Core::CurrentOrder.current_order 在开发中仅使用“current_order”工作正常,但不在生产中。 那么我试图在我的视图文件中要求它像这样: require ‘spree/core/current_order’ 我也尝试过这些其他解决方案的排列: 如何在主应用程序中合并Rails引擎ApplicationController方法? 一种从引擎到应用程序添加before_filter的方法 Rails 3.1:在客户端应用程序中公开引擎助手的更好方法 但我已经忘记了我实际做了什么。 有人可以指出我正确的方向吗? 也许我错误地在上面的链接中实现了解决方案? 这是我在制作中遇到的错误: 2012-06-21T09:59:08 + 00:00 app [web.1]:ActionView :: Template :: Error(Spree :: Core :: CurrentOrder:Module的未定义方法`current_order’): 如果我用current_order注释掉代码行,那么一切都在生产中。 我认为这是生产中装载的方式吗? 但这是我第一次尝试部署,所以我不太了解开发和生产之间的差异。 提前致谢!