gpt4 book ai didi

ruby-on-rails - 设计更改默认路由不起作用

转载 作者:行者123 更新时间:2023-12-04 06:22:25 25 4
gpt4 key购买 nike

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

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 =/登录

/users/sign_up =/signup

/users/sign_out =/signout

/users/edit =/edit

我正在使用 Devise 1.3.4 和 Rails 3.0.7。

提前致谢!

最佳答案

好的,我明白了,我只是把它打出来以帮助其他新手!

除非以这种方式编码,否则路线本身会改变,但导航链接不会改变。尝试 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 %>

我当然希望这能帮助那些像我一样迷路并且刚刚进入设计和 RoR 的人。它会让你很好地理解如何让路线以一种简单的方式看起来像你想要的那样,但仍然有效。祝你好运!

关于ruby-on-rails - 设计更改默认路由不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6000222/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com