【问题标题】:How can I move to other user's Profile page?如何移动到其他用户的个人资料页面?
【发布时间】:2014-11-12 13:57:18
【问题描述】:

我有一个用户,他的用户列表中有一些朋友。我如何查看他们的个人资料页面?我在哪里可以这样做?我是这样做的:

 % @accounts.each do |account| %>
      <tr>
        <td><%= link_to account.name, account %></td>

但我总是转移到我的 current_account 而不是我想要的用户。

任何帮助将不胜感激。

--已编辑--

这是我的表演课:

<%- model_class = Account -%>
<div class="page-header">
  <h1><%=t '.title', :default => model_class.model_name.human.titleize %></h1>
</div>

<dl class="dl-horizontal">
  <dd><%= image_tag @account.profile_photo.url %></dd>
   <dt><strong><%= model_class.human_attribute_name(:name) %>:</strong></dt>
  <dd><%= @account.name %></dd>
  <dt><strong><%= model_class.human_attribute_name(:gender) %>:</strong></dt>
  <dd><%= @account.gender %></dd>
  <dt><strong><%= model_class.human_attribute_name(:age) %>:</strong></dt>
  <dd><%= @account.age %></dd>
  <dt><strong><%= model_class.human_attribute_name("Date Of Birth") %>:</strong></dt>
  <dd><%= (@account.year_Of_Birth.to_s) +"/"+(@account.month_Of_Birth.to_s)+"/"+(@account.day_Of_Birth.to_s)  %></dd>
  <dt><strong><%= model_class.human_attribute_name(:country) %>:</strong></dt>
  <dd><%= @account.country %></dd>
  <dt><strong><%= model_class.human_attribute_name(:favorite_Sport) %>:</strong></dt>
  <dd><%= @account.favorite_Sport %></dd>
  <dt><strong><%= model_class.human_attribute_name(:account_id) %>:</strong></dt>

</dl>

【问题讨论】:

  • account#show 作用域为当前用户吗?
  • 是的,它是当前用户,我不知道该放什么

标签: ruby-on-rails ruby show


【解决方案1】:

根据您提供的内容,如果您希望其他用户能够查看其他个人资料页面,则您不能将 #show 范围限定为当前用户。而是做这样的事情:

class AccountsController < ApplicationController
   def show
     @account = Account.find(params[:id])
   end
end

【讨论】:

  • 我刚刚用显示视图编辑了我的帖子。现在我收到这个错误 undefined method `profile_photo' for nil:NilClass
  • 听起来像是一个不同的错误 - 你最好打开另一个问题。
猜你喜欢
  • 2016-04-06
  • 2012-01-24
  • 2020-01-23
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多