【发布时间】:2015-03-16 03:15:52
【问题描述】:
我知道了,所以我有一个临床医生正在与之交谈的独特患者的列表。我可以调出有关患者的详细信息,但无法调出与相关评论有关的任何内容。
app\views\cmets\index.html.erb
<% @comments.map(&:patient).uniq.each_with_index do |comment, index| %>
<div class="profile-post color-one">
<span class="profile-post-numb"><%= index+1 %></span>
<div class="profile-post-in">
<h3 class="heading-xs"><a><%= link_to "#{comment.first_name} #{comment.last_name}", comment_path(comment) %></a></h3>
<p><%= comment.diagnosis %><i class="pull-right"><%= link_to "Edit", edit_comment_path(comment) %> <%= link_to "Delete", comment_path(comment), method: :delete, data: {confirm: 'Are you sure you want to delete'} %></i></p>
</div>
</div>
<% end %>
link_to 也被破坏了,因为它们应该指向评论页面,但传递的是 patient.id 而不是 comment.id。
cmets_conrtoller.rb
def index
@comments = current_clinician.comments
end
comment.rb
class Comment < ActiveRecord::Base
belongs_to :clinician
belongs_to :patient
end
【问题讨论】:
标签: ruby-on-rails loops uniq do-loops