我对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” –