Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/53.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 我使用什么路径来引用当前用户的路径';她的个人资料?设计_Ruby On Rails_Ruby_Rest_Devise_Routes - Fatal编程技术网

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