简体   繁体   English

在Rails.application.routes.draw Rails 5.2内使用引擎路由

[英]Use Engine Routes inside of Rails.application.routes.draw Rails 5.2

I'm currently using a custom build of a gem that hasn't been updated to work with Rails 5.2 as of now. 我当前使用的是宝石的自定义版本,到目前为止,该宝石尚未更新为可与Rails 5.2一起使用。 I've extracted the core files and now I'm faced with an issue where I need to access the routes for the engine internally. 我已经提取了核心文件,现在遇到一个问题,我需要在内部访问引擎的路由。 All folders for the gem, have the namespace payola - which allows me to access its resources. gem的所有文件夹都具有命名空间payola-这使我可以访问其资源。 How can I setup my routes to take into account the namespaced routes for the gem, without including the reference to the engine itself (which is causing duplicates). 如何设置我的路由以考虑gem的命名空间路由,而不包括对引擎本身的引用(这会导致重复)。 My routes file is below. 我的路线文件如下。 When I add the routes to the Rails.application.routes.draw alone, its unable to find the controllers for it. 当我将路线单独添加到Rails.application.routes.draw时,它无法为其找到控制器。

routes.rb 的routes.rb

Rails.application.routes.draw do
  get 'mobile_search/index'
  mount Payola::Engine => '/payola', as: :payola
  mount ActionCable.server => '/cable'
  require 'sidekiq/web'
  mount Sidekiq::Web => '/sidekiq'
  mount Resque::Server, :at => "/resque"
  mount CountryStateSelect::Rails::Engine, at: "/"

  devise_for :admins
  devise_for :users, path: '', path_names: {sign_in: 'login', sign_out: 'logout', sign_up: 'signup'}, controllers: {registrations: 'users/registrations'}

  devise_scope :user do
    put 'user_change_plan', :to => 'users/registrations#user_change_plan'
    authenticated do
      root to: 'user_dashboard#index', as: 'authenticated_user_root'
    end
    unauthenticated do
      root to: 'home#index', as: 'unauthenticated_user_root'
    end
  end

  devise_scope :admin do
    authenticated do
      root to: 'admin_dashboard#admin', as: 'authenticated_admin_root'
    end

    unauthenticated do
      root to: 'home#index', as: 'unauthenticated_admin_root'
    end
  end

  resources :after_registration_wizard, only: [:show]

  root 'home#index'
end

# Payola

Payola::Engine.routes.draw do
  match '/buy/:product_class/:permalink'  => 'transactions#create',   via: :post, as: :buy
  match '/confirm/:guid'                  => 'transactions#show',     via: :get,  as: :confirm
  match '/status/:guid'                   => 'transactions#status',   via: :get,  as: :status

  match '/subscribe/:plan_class/:plan_id' => 'subscriptions#create',   via: :post,   as: :subscribe
  match '/confirm_subscription/:guid'     => 'subscriptions#show',     via: :get,    as: :confirm_subscription
  match '/subscription_status/:guid'      => 'subscriptions#status',   via: :get,    as: :subscription_status
  match '/cancel_subscription/:guid'      => 'subscriptions#destroy',  via: :delete, as: :cancel_subscription
  match '/change_plan/:guid'              => 'subscriptions#change_plan', via: :post, as: :change_subscription_plan
  match '/change_quantity/:guid'          => 'subscriptions#change_quantity', via: :post, as: :change_subscription_quantity
  match '/update_card/:guid'              => 'subscriptions#update_card', via: :post, as: :update_card

  match '/update_customer/:id'            => 'customers#update', via: :post, as: :update_customer

  match '/create_card/:customer_id'       => 'cards#create', via: :post, as: :create_card
  match '/destroy_card/:id/:customer_id'  => 'cards#destroy', via: :delete, as: :destroy_card

  mount StripeEvent::Engine => '/events'
end

I created a scoped module that would render the same results as the engine itself. 我创建了一个有作用域的模块,该模块将呈现与引擎本身相同的结果。

routes.rb 的routes.rb

 scope :module => "payola" do
    match '/buy/:product_class/:permalink'  => 'transactions#create',   via: :post, as: :buy
    match '/confirm/:guid'                  => 'transactions#show',     via: :get,  as: :confirm
    match '/status/:guid'                   => 'transactions#status',   via: :get,  as: :status

    match '/subscribe/:plan_class/:plan_id' => 'subscriptions#create',   via: :post,   as: :subscribe
    match '/confirm_subscription/:guid'     => 'subscriptions#show',     via: :get,    as: :confirm_subscription
    match '/subscription_status/:guid'      => 'subscriptions#status',   via: :get,    as: :subscription_status
    match '/cancel_subscription/:guid'      => 'subscriptions#destroy',  via: :delete, as: :cancel_subscription
    match '/change_plan/:guid'              => 'subscriptions#change_plan', via: :post, as: :change_subscription_plan
    match '/change_quantity/:guid'          => 'subscriptions#change_quantity', via: :post, as: :change_subscription_quantity
    match '/update_card/:guid'              => 'subscriptions#update_card', via: :post, as: :update_card

    match '/update_customer/:id'            => 'customers#update', via: :post, as: :update_customer

    match '/create_card/:customer_id'       => 'cards#create', via: :post, as: :create_card
    match '/destroy_card/:id/:customer_id'  => 'cards#destroy', via: :delete, as: :destroy_card
    mount StripeEvent::Engine => '/events'
  end

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM