所以我有一个应用程序,它有一个管理控制器面板来监控应用程序内容。如何为管理员面板创建sign_out路线?
我的routes.rb:
class MainSite
def self.matches?(request)
request.subdomain.blank? || request.subdomain == 'www'
request.subdomain.blank? ||
request.subdomain == 'what'
end
end
What::Application.routes.draw do
post '/rate' => 'rater#create', :as => 'rate'
# mount RailsAdmin::Engine => '/admin', as: 'rails_admin'
# mount RailsAdmin::Engine => '/saas_admin', :as => 'rails_admin'
# devise_for :saas_admins
devise_for :saas_admins, :path => "admin"
match "/videos/notify", :to => "saas_admin/videos#notify", via: :post
namespace "saas_admin", :path => "admin" do
root :to => "subscriptions#index"
resources :tags
resources :taggings
resources :comments
resources :app_settings, except: [:new, :destroy]
resources :subscriptions do
member do
post :charge
end
end
resources :accounts
resources :subscription_plans, :path => 'plans'
resources :subscription_discounts, :path => 'discounts'
resources :subscription_affiliates, :path => 'affiliates'
match "/videos/authorize_upload", :to => "videos#authorize_upload", :via => :post
scope '/content' do
root :to => "studios#index", :as => 'content'
resources :videos, :only => [:create, :update, :index, :show, :destroy] do
end
resources :encoded_videos, :only => [:show] do
end
resources :studios do
resources :films do
resources :clips do
end
end
end
end
end
# Routes for the public site
constraints MainSite do
# Homepage
# root :to => "static_pages#home"
# Static Pages
get '/faq' => 'static_pages#faq', :as => 'faq'
get '/webclip', to: 'static_pages#webclip', as: 'webclip'
get '/my_queue', to: 'users#my_queue', as: 'my_queue'
get '/learn_more', to: 'static_pages#learn_more', as: 'learn_more'
# Account Signup Routes
get '/signup' => 'accounts#plans', :as => 'plans'
get '/signup/d/:discount' => 'accounts#plans'
get '/signup/thanks' => 'accounts#thanks', :as => 'thanks'
get '/signup/create/:discount' => 'accounts#create', :as => 'create', :defaults => { :discount => nil }
get '/signup/:plan/:discount' => 'accounts#new' #, :as => 'new_account'
get '/signup/:plan' => 'accounts#new', :as => 'new_account'
get 'queue_toggle/:id' => 'clips#queue_toggle', as: :queue_toggle
post 'signup' => 'accounts#new', as: :select_plan
match 'add_tags' => 'clips#add_tags', via: :post
resources :clips, :only => [:index, :show] do
resources :comments
end
resources :videos, :only => [:show] do
end
resources :encoded_videos, :only => [:show] do
end
# Catch-all that just loads views from app/views/content/* ...
# e.g, http://yoursite.com/content/about -> app/views/content/about.html.erb
#
get '/content/:action' => 'content'
end
devise_for :users, :path => "user"
#
# Account / User Management Routes
#
#resources :users
resources :account_steps
resource :account do
resources :users
member do
get :dashboard, :thanks, :plans, :canceled
match 'billing' => "accounts#billing", via: [ :get, :post ]
match 'plan' => "accounts#plan", via: [ :get, :post ]
match 'cancel' => "accounts#cancel", via: [ :get, :post ]
match 'paypal' => "accounts#paypal", via: [ :get, :post ]
match 'plan_paypal' => "accounts#plan_paypal", via: [ :get, :post ]
match 'add_organization' => 'accounts#add_organization', via: :put
match 'add_credit_details' => 'accounts#add_credit_details', via: :put
match 'update_organization' => 'accounts#update_organization', via: :put
match 'update_plan' => 'accounts#update_plan', via: :put
end
end
get 'index' => 'static_pages#index', as: :index
root :to => "static_pages#home"
# The priority is based upon order of creation:
# first created -> highest priority.
# Sample of regular route:
# match 'products/:id' => 'catalog#view'
# Keep in mind you can assign values other than :controller and :action
# Sample of named route:
# match 'products/:id/purchase' => 'catalog#purchase', :as => :purchase
# This route can be invoked with purchase_url(:id => product.id)
# Sample resource route (maps HTTP verbs to controller actions automatically):
# resources :products
# Sample resource route with options:
# resources :products do
# member do
# get 'short'
# post 'toggle'
# end
#
# collection do
# get 'sold'
# end
# end
# Sample resource route with sub-resources:
# resources :products do
# resources :comments, :sales
# resource :seller
# end
# Sample resource route with more complex sub-resources
# resources :products do
# resources :comments
# resources :sales do
# get 'recent', :on => :collection
# end
# end
# Sample resource route within a namespace:
# namespace :admin do
# # Directs /admin/products/* to Admin::ProductsController
# # (app/controllers/admin/products_controller.rb)
# resources :products
# end
# You can have the root of your site routed with "root"
# just remember to delete public/index.html.
# root :to => "welcome#index"
# See how all your routes lay out with "rake routes"
# This is a legacy wild controller route that's not recommended for RESTful applications.
# Note: This route will make all actions in every controller accessible via GET requests.
# match ':controller(/:action(/:id(.:format)))'
end
我猜它会是这样的:
get '/admin/sign_out' => 'saasadmin/accounts#sign_out', as: sign_out
这里的任何帮助都会很棒!
谢谢!
答案 0 :(得分:3)
您应该已经拥有由Devise定义的路线。您可以使用以下内容创建链接:
<%= link_to 'SIGN OUT', destroy_saas_admin_session_path , method: :delete %>
答案 1 :(得分:0)
<强>路线强>
要添加到已接受的答案,您应该了解Rails的Resourceful路由结构:
按照惯例,Rails使用此HTTP动词结构来定义各种资源的路由
当您从控制器调用admin sessions#destroy
操作时,您实际上需要使用DELETE
动词,如上所述。这就是为什么您收到no routes
请求时出现GET
错误的原因,以及使用method: :delete