2

我正在使用设计,我想自定义它的网址:

users/sign_in --> account/login
users/sign_up --> account/register
users/edit    --> account/profile
...

现在我的routes.rb样子是这样的:

  devise_scope :user do
    get '/account/login' => 'devise/sessions#new'
    post 'account/login' => 'devise/sessions#create', as: :user_session
    delete 'account/logout' => 'devise/sessions#destroy', as: :destroy_user_session

    post 'account/password' => 'devise/passwords#update', as: :user_password
    get 'account/password/forgot' => 'devise/passwords#new', as: :new_user_password
    get 'account/password/edit' => 'devise/passwords#edit', as: :edit_user_password
    put 'account/password' => 'devise/passwords#update'

    get 'account/cancel' => 'devise/registrations#cancel', as: :cancel_user_registration
    post 'account' => 'devise/registrations#create', as: :user_registration
    get 'account/register' => 'devise/registrations#new', as: :new_user_registration
    get 'account' => 'devise/registrations#edit', as: :edit_user_registration
    put 'account' => 'devise/registrations#edit'
    delete 'account' => 'devise/registrations#destroy'
  end
  devise_for :users

我设法不覆盖profile, forgot, register错误login

因此,当我单击通用设计登录表单中的“注册”链接时,我在浏览器中被重定向到/register但是当我单击“登录”链接时,我仍然被重定向到/users/sign_in而不是login.

我尝试了路线,但没有match运气post + get。我知道如果我自己生成表格,我可以决定链接的外观,但我更喜欢使用通用设计表格,而且我很好奇为什么其他路线有效。

运行rake routes会产生这个(我的路线中的前五行):

        new_user_session GET    /account/login(.:format)           devise/sessions#new
            user_session POST   /account/login(.:format)           devise/sessions#create
    destroy_user_session DELETE /account/logout(.:format)          devise/sessions#destroy
           user_password POST   /account/password(.:format)        devise/passwords#update
       new_user_password GET    /account/password/forgot(.:format) devise/passwords#new
      edit_user_password GET    /account/password/edit(.:format)   devise/passwords#edit
        account_password PUT    /account/password(.:format)        devise/passwords#update
cancel_user_registration GET    /account/cancel(.:format)          devise/registrations#cancel
       user_registration POST   /account(.:format)                 devise/registrations#create
   new_user_registration GET    /account/register(.:format)        devise/registrations#new
  edit_user_registration GET    /account(.:format)                 devise/registrations#edit
                 account PUT    /account(.:format)                 devise/registrations#edit
                         DELETE /account(.:format)                 devise/registrations#destroy
        new_user_session GET    /users/sign_in(.:format)           devise/sessions#new
                         POST   /users/sign_in(.:format)           devise/sessions#create
    destroy_user_session DELETE /users/sign_out(.:format)          devise/sessions#destroy
                         POST   /users/password(.:format)          devise/passwords#create
                         GET    /users/password/new(.:format)      devise/passwords#new
                         GET    /users/password/edit(.:format)     devise/passwords#edit
                         PUT    /users/password(.:format)          devise/passwords#update
                         GET    /users/cancel(.:format)            devise/registrations#cancel
                         POST   /users(.:format)                   devise/registrations#create
                         GET    /users/sign_up(.:format)           devise/registrations#new
                         GET    /users/edit(.:format)              devise/registrations#edit
                         PUT    /users(.:format)                   devise/registrations#update
                         DELETE /users(.:format)                   devise/registrations#destroy
                root        /                                  posts#show

更新:我现在正在模仿设计的所有路线(请参阅更新的 routes.rb)。但我仍然被重定向到/users/sign_in

4

2 回答 2

3

你可以试试这个,这很有效

查看更多帮助设计 wiki

   devise_for :users, :path => '', :path_names => {:sign_in => 'login', :sign_out => 'logout'}
于 2013-04-20T10:21:24.497 回答
2

这应该有效。还要删除 /account 并将路径帐户添加到您的路由文件中,就像我在下面所做的那样。

  devise_scope :user, path: "account" do
    get "login", :to => "devise/sessions#new", :as => "login"
    get "signup" => "users/registrations#new", :as => "register"
    get "edit" => "edit_user_registration", :as => "edit"
  end
于 2013-04-20T13:40:04.183 回答