无法覆盖设计路线

时间:2013-04-20 10:15:56

标签: ruby-on-rails ruby devise routes rake

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

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

我尝试了matchpost + 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

2 个答案:

答案 0 :(得分:3)

你可以尝试这个,这是有用的

查看更多帮助devise wiki

   devise_for :users, :path => '', :path_names => {:sign_in => 'login', :sign_out => 'logout'}

答案 1 :(得分: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