设计更改默认路由不起作用

发布于 2024-11-07 20:21:33 字数 812 浏览 2 评论 0原文

当我关注 Devise Wiki https://github.com/plataformatec/devise/wiki/How-To:-Change-the-default-sign_in-and-sign_out-routes ,我的默认路由名称根本没有改变,这里是我的代码:

MyApp::Application.routes.draw do
  root :to => "profile#index"     

  devise_for :users
  namespace :user do
    root :to => "profile#index"
  end

  as :user do
  get "/login" => "devise/sessions#new"
  get "/signup" => "devise/registrations#new"
  end

两个路线更改不起作用,所以我停下来。

我如何更改它,以便我的路线为:

/users/sign_in = /login

/users/sign_up = /signup

/users/sign_out = /signout

/users/edit = /edit

我正在使用 Devise 1.3.4 和 Rails 3.0.7 。

先感谢您!

when i follow the Devise Wiki at https://github.com/plataformatec/devise/wiki/How-To:-Change-the-default-sign_in-and-sign_out-routes , my default route names do not change at all, here is my code :

MyApp::Application.routes.draw do
  root :to => "profile#index"     

  devise_for :users
  namespace :user do
    root :to => "profile#index"
  end

  as :user do
  get "/login" => "devise/sessions#new"
  get "/signup" => "devise/registrations#new"
  end

The two route changes didnt work so i stopped.

How do i change it so my routes are:

/users/sign_in = /login

/users/sign_up = /signup

/users/sign_out = /signout

/users/edit = /edit

I am using Devise 1.3.4 and Rails 3.0.7.

Thank you in advance!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

波浪屿的海角声 2024-11-14 20:21:33

好吧,我明白了,我只是输入这个来帮助其他新手!

路线本身会改变,但导航链接不会改变,除非以这种方式编码。
尝试 http://localhost:3000/loginhttp://localhost:3000/users/sign_up,它们是相同的,但只需手动输入即可。

我的新代码如下所示(导航链接和路线配置在一起):

routes.rb:

MyApp::Application.routes.draw do

  devise_for :users do
    root :to => "devise/registrations#new"
    get "/" => "devise/registrations#new"
    post '/' => 'registrations#new', :as => :new_user_registration 
    match '/', :to => 'devise/registrations#new'    
    get "/edit" => "devise/registrations#edit"
    match '/edit', :to => 'devise/registrations#edit'   
    get "/login" => "devise/sessions#new"
    match '/login', :to => 'devise/sessions#new'
    get "/logout" => "devise/sessions#destroy"
    match '/logout', :to => 'devise/sessions#destroy'   
  end



  namespace :user do
    root :to => "profile#index"
  end

views/devise/menu/_login_items.html.erb :

<% if user_signed_in? %>
  <li>
  <%= link_to('Logout', logout_path) %>        
  </li>
<% else %>
  <li>
  <%= link_to('Login', login_path)  %>  
  </li>
<% end %>

views/devise/menu/_registration_items.html.erb

<% if user_signed_in? %>
  <li>
  <%= link_to('Edit account', edit_path) %>
  </li>
<% else %>
  <li>
  <%= link_to('Sign up', root_path)  %>
  </li>
<% end %>

我当然希望这能帮助那些像我一样迷失方向并刚刚接触 devise 和 RoR 的人。它将让您更好地了解如何以简单的方式让路线看起来像您想要的那样,但仍然有效。祝你好运!

OK i figured it out, ill just type this out to help other newbies!

The routes themselves change but not the navigation links unless coded that way.
try http://localhost:3000/login and http://localhost:3000/users/sign_up, they are the same thing but just have to be typed in manually.

My new code looks like this ( navigation links & route configurations together):

routes.rb:

MyApp::Application.routes.draw do

  devise_for :users do
    root :to => "devise/registrations#new"
    get "/" => "devise/registrations#new"
    post '/' => 'registrations#new', :as => :new_user_registration 
    match '/', :to => 'devise/registrations#new'    
    get "/edit" => "devise/registrations#edit"
    match '/edit', :to => 'devise/registrations#edit'   
    get "/login" => "devise/sessions#new"
    match '/login', :to => 'devise/sessions#new'
    get "/logout" => "devise/sessions#destroy"
    match '/logout', :to => 'devise/sessions#destroy'   
  end



  namespace :user do
    root :to => "profile#index"
  end

the views/devise/menu/_login_items.html.erb :

<% if user_signed_in? %>
  <li>
  <%= link_to('Logout', logout_path) %>        
  </li>
<% else %>
  <li>
  <%= link_to('Login', login_path)  %>  
  </li>
<% end %>

the views/devise/menu/_registration_items.html.erb

<% if user_signed_in? %>
  <li>
  <%= link_to('Edit account', edit_path) %>
  </li>
<% else %>
  <li>
  <%= link_to('Sign up', root_path)  %>
  </li>
<% end %>

I certainly hope this helps people who were lost like me and just got into both devise and RoR. it will give you a good understanding on how to get the routes to look the way you want it to be in a simple manner, yet still work. Good luck!

贵在坚持 2024-11-14 20:21:33

这些维基页面是非常好的资源。

https://github。 com/plataformatec/devise/wiki/How-To:-Change-the-default-sign_in-and-sign_out-routes

介绍如何更改登录/注销路线,但这也可以轻松应用于注册。看看

These wiki pages are very good resources.

https://github.com/plataformatec/devise/wiki/How-To:-Change-the-default-sign_in-and-sign_out-routes

Tells how to change login/logout routes but that can easily be applied to signup too. Take a look

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文