我對Ruby/Rails中的應用程序有一個問題路由。我有兩種不同的模型,一個用戶和一個管理員。首先,我設置了用戶,並獨立運行。用戶有「sign_in」,「signed_out」,「account_settings」,「登錄」方法等。Rails 4路由
然後我創建了一個管理模型。這與用戶非常相似,除了它有能力刪除/禁止用戶模型。問題是,我想使用類似的路由方法,除了前綴「/ admin /」。我正在研究範圍和命名空間,但我無法正確地路由所有內容。這就是我的config/routes.rb
文件看起來像一個時刻:
Rails.application.routes.draw do
root 'home#index'
scope 'admin' do
get "sign_in" => "admin#sign_in"
post "sign_in" => "admin#login"
get "signed_out" => "admin#signed_out"
end
get "sign_in" => "authentication#sign_in"
post "sign_in" => "authentication#login"
get "signed_out" => "authentication#signed_out"
get "new_user" => "authentication#new_user"
put "new_user" => "authentication#register"
get "account_settings" => "authentication#account_settings"
put "account_settings" => "authentication#set_account_info"
get "forgot_password" => "authentication#forgot_password"
put "forgot_password" => "authentication#send_password_reset_instructions"
get "password_reset" => "authentication#password_reset"
put "password_reset" => "authentication#new_password"
end
有什麼,我做錯了什麼?我要爲管理員航線是localhost:3000/admin/sign_in
和localhost:3000/admin/signed_out
和路線對於用戶而言,localhost:3000/sign_in
和localhost:3000/signed_out
感謝
增加:的rake routes
輸出如下
$ rake routes
Prefix Verb URI Pattern Controller#Action
root GET/ home#index
sign_in GET /admin/sign_in(.:format) admin#sign_in
POST /admin/sign_in(.:format) admin#login
signed_out GET /admin/signed_out(.:format) admin#signed_out
account_settings GET /admin/account_settings(.:format) admin#account_settings
GET /sign_in(.:format) authentication#sign_in
POST /sign_in(.:format) authentication#login
GET /signed_out(.:format) authentication#signed_out
new_user GET /new_user(.:format) authentication#new_user
PUT /new_user(.:format) authentication#register
GET /account_settings(.:format) authentication#account_settings
PUT /account_settings(.:format) authentication#set_account_info
forgot_password GET /forgot_password(.:format) authentication#forgot_password
PUT /forgot_password(.:format) authentication#send_password_reset_instructions
password_reset GET /password_reset(.:format) authentication#password_reset
PUT /password_reset(.:format) authentication#new_password
我怎樣才能創建自定義幫助程序路徑,以便我不需要在每個表單/鏈接中手動輸入它們。
編輯:
新航線信息文件如下
root_path GET/ home#index
admin_sign_in_path GET /admin/sign_in(.:format) admin/admin#sign_in
POST /admin/sign_in(.:format) admin/admin#login
admin_signed_out_path GET /admin/signed_out(.:format) admin/admin#signed_out
admin_account_settings_path GET /admin/account_settings(.:format) admin/admin#account_settings
sign_in_path GET /sign_in(.:format) authentication#sign_in
POST /sign_in(.:format) authentication#login
signed_out_path GET /signed_out(.:format) authentication#signed_out
new_user_path GET /new_user(.:format) authentication#new_user
PUT /new_user(.:format) authentication#register
account_settings_path GET /account_settings(.:format) authentication#account_settings
PUT /account_settings(.:format) authentication#set_account_info
forgot_password_path GET /forgot_password(.:format) authentication#forgot_password
PUT /forgot_password(.:format) authentication#send_password_reset_instructions
password_reset_path GET /password_reset(.:format) authentication#password_reset
PUT /password_reset(.:format) authentication#new_password
現在它甚至發送'localhost:3000/sign_in'到管理員登錄頁面 – Josh
我不確定,但是您是否嘗試將其更改爲'scope'/ admin''? – DanneManne
在設計路線時使用「$ rake routes」 –