[英]Displaying a link in microposts and comments that links to the author's profile?
[英]Displaying microposts' comments for user
基於Micropost在用戶頁面上的評論(Ruby on Rails) ,我能夠為每個micropost添加新評論。 但是,我無法在同一頁面上顯示每個帖子的評論。 下面的代碼沒有引發任何錯誤,因此我認為每個微博的注釋未正確分配,因此無法顯示。
用戶 > 微博 > 評論
users_controller.rb
def show
@user = Account.find(params[:id])
@microposts = @user.microposts
@micropost = Micropost.new
@comments = @micropost.comments
@comment = Comment.new
end
microposts / _micropost.html.erb
<li>
<span class="content"><%= micropost.content %></span>
<span class="timestamp">
Posted <%= time_ago_in_words(micropost.created_at) %> ago.
</span>
<span class="comments">
<% if micropost.comments.any? %>
<ul class="comments">
<%= render @comments%>
</ul>
<% end %>
<%= render "shared/form_comment", micropost: micropost %>
</span>
</li>
comments / _comment.html.erb
<li>
<span class="content"><%= comment.content %></span>
<span class="timestamp">
Posted <%= time_ago_in_words(comment.created_at) %> ago.
</span>
</li>
<li>
<span class="content"><%= micropost.content %></span>
<span class="timestamp">
Posted <%= time_ago_in_words(micropost.created_at) %> ago.
</span>
<span class="comments">
<ul class="comments">
<%= render micropost.comments %> # you can leave out the #any?
</ul>
</span>
</li>
將<%= render @comments%>
更改為<%= render micropost.comments %>
以遍歷特定帖子的注釋,而不是使用常規注釋循環。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.