gpt4 book ai didi

ruby-on-rails - 路由到 current_user 路径

转载 作者:数据小太阳 更新时间:2023-10-29 08:23:49 24 4
gpt4 key购买 nike

所以我在顶部有一个 Bootstrap 导航栏。

我想链接到当前用户的编辑路径,但我总是得到错误:

ActionController::RoutingError at /blog

No route matches {:action=>"edit", :controller=>"users"}

这就是我目前正在尝试的:

<% if current_user %> <--! user logged in? -->
<% @user ||= current_user %>
<%= link_to 'Settings', edit_user_path %>
<% end %>

我在/user/1/页面上没有这个错误,但我在其他任何地方都有。

也试过这个,但没有帮助:

def edit
if params[:id]
@user = User.find(params[:id])
else
@user = current_user
end
end

最佳答案

试试这个,

<%= link_to 'Settings', edit_user_path(current_user)  %>

关于ruby-on-rails - 路由到 current_user 路径,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15407714/

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