Ruby on rails 我使用什么路径来引用当前用户的路径';她的个人资料?设计
我的应用程序的用户在创建个人资料时上传一个化身。以下是我如何在导航栏中显示其个人资料图片的小版本:Ruby on rails 我使用什么路径来引用当前用户的路径';她的个人资料?设计,ruby-on-rails,ruby,rest,devise,routes,Ruby On Rails,Ruby,Rest,Devise,Routes,我的应用程序的用户在创建个人资料时上传一个化身。以下是我如何在导航栏中显示其个人资料图片的小版本: <li><%= link_to image_tag current_user.avatar(:nav) %></li> 我目前正在使用Desive进行身份验证 这是我的用户控制器 class UsersController < ApplicationController def show @user = User.find_by_usern
<li><%= link_to image_tag current_user.avatar(:nav) %></li>
我目前正在使用Desive进行身份验证
这是我的用户控制器
class UsersController < ApplicationController
def show
@user = User.find_by_username(params[:id])
end
def user_params
params.require(:user).permit(:avatar)
end
end
class UsersController
根据您提供的路线,您的用户档案将是users\show
。因此,您要查找的路径应该是user\u path
#app/controllers/users_controller.rb
class UsersController < ApplicationController
def show
@user = User.find(params[:id]
...
end
end
#app/controllers/users_controller.rb
类UsersController
然后在
app/views/users/show.html.erb
中显示用户的配置文件信息。根据您提供的路线,您的用户配置文件将是users\show
。因此,您要查找的路径应该是user\u path
#app/controllers/users_controller.rb
class UsersController < ApplicationController
def show
@user = User.find(params[:id]
...
end
end
#app/controllers/users_controller.rb
类UsersController
然后在
app/views/users/show.html.erb
中显示用户的配置文件信息。根据您提供的路线,您的用户配置文件将是users\show
。因此,您要查找的路径应该是user\u path
#app/controllers/users_controller.rb
class UsersController < ApplicationController
def show
@user = User.find(params[:id]
...
end
end
#app/controllers/users_controller.rb
类UsersController
然后在
app/views/users/show.html.erb
中显示用户的配置文件信息。根据您提供的路线,您的用户配置文件将是users\show
。因此,您要查找的路径应该是user\u path
#app/controllers/users_controller.rb
class UsersController < ApplicationController
def show
@user = User.find(params[:id]
...
end
end
#app/controllers/users_controller.rb
类UsersController
然后在app/views/users/show.html.erb中显示用户的个人资料信息。尝试:
<li><%= link_to (image_tag current_user.avatar(:nav)), user_path(current_user.id) %></li>
您也可以只使用“当前用户”而不使用“当前用户.id”试试:
<li><%= link_to (image_tag current_user.avatar(:nav)), user_path(current_user.id) %></li>
您也可以只使用“当前用户”而不使用“当前用户.id”试试:
<li><%= link_to (image_tag current_user.avatar(:nav)), user_path(current_user.id) %></li>
您也可以只使用“当前用户”而不使用“当前用户.id”试试:
<li><%= link_to (image_tag current_user.avatar(:nav)), user_path(current_user.id) %></li>
您也可以只使用“current_user”而不使用“current_user.id”它解决了这个错误,但它让我发现:
没有路由匹配{:controller=>“users”,:action=>“show”}缺少必需的键:[:id]
@DylanRichards,显示操作需要一个参数id
,它是您要访问其配置文件页面的用户的id。将其用作用户路径(当前用户)
或用户路径(id:current\u user.id)
。看起来我们越来越近了。我选择使用用户路径(当前用户)。现在出现此错误:
undefined method为“/users/Delacram”符号化密钥“:String
Delacram是当前用户的用户名。我不确定您为什么要在那里获取用户名,但如果您想使用用户名
,则可以执行@user=user。按用户名查找(参数[:username])
。请确保在参数
散列中为用户名
使用适当的键。是否可以发布不起作用的内容和错误日志。是否验证参数
散列的内容?它解决了该错误,但导致我出现以下错误:没有路由匹配{:controller=>“users”,:action=>“show”}缺少必需的键:[:id]
@DylanRichards,显示操作需要一个参数id
,该参数是您要访问其配置文件页面的用户的id。将其用作user\u path(current\u user)
或user\u path(id:current\u user.id)
。看起来我们越来越近了。我已选择使用user\u path(current\u user)。现在出现此错误:
undefined method为“/users/Delacram”符号化密钥“:String
Delacram是当前用户的用户名。我不确定您为什么要在那里获取用户名,但如果您想使用用户名
,则可以执行@user=user。按用户名查找(参数[:username])
。请确保在参数
散列中为用户名
使用适当的键。是否可以发布不起作用的内容和错误日志。是否验证参数
散列的内容?它解决了该错误,但导致我出现以下错误:没有路由匹配{:controller=>“users”,:action=>“show”}缺少必需的键:[:id]
@DylanRichards,显示操作需要一个参数id
,该参数是您要访问其配置文件页面的用户的id。将其用作user\u path(current\u user)
或user\u path(id:current\u user.id)
。看起来我们越来越近了。我已选择使用user\u path(current\u user)。现在出现此错误:
undefined method为“/users/Delacram”符号化密钥“:String
Delacram是当前用户的用户名。我不确定您为什么要在那里获取用户名,但如果您想使用用户名
,则可以执行@user=user。按用户名查找(参数[:username])
。请确保在参数
散列中为用户名
使用适当的键。是否可以发布不起作用的内容和错误日志。是否验证参数
散列的内容?它解决了该错误,但导致我出现以下错误:没有路由匹配{:controller=>“users”,:action=>“show”}缺少必需的键:[:id]
@DylanRichards,显示操作需要一个参数id
,该参数是您要查看其配置文件页面的用户的id