rails 添加发送消息时显示 ActiveRecord_Associations 错误 link

rails showing ActiveRecord_Associations error while adding a send message link

我有一个 rails 应用程序,用户可以在其中添加 post,其他用户可以对其发表评论 我正在尝试向发表评论的用户添加直接消息 link,我按照关于 Whosebug

的建议尝试了这样的事情

_form.html.erb

<%= form_for :conversation, url: :conversations, html: { class: "" } do |f| %>
<div class="form-group">
  <%= f.label :recipients %>
  <%= hidden_field_tag(:recipient_id, "#{@user.id}") %></div>
<div class="form-group">
  <%= f.label :subject %>
  <%= f.text_field :subject, placeholder: "Subject", class: "form-control" %>
</div>
<div class="form-group">
  <%= f.label :message %>
  <%= f.text_area :body, class: 'form-control',placeholder: "Type your message here", rows: 4  %>
</div>

<%= f.submit "Send Message", class: "btn btn-success" %>

<% end %>

show.html.erb

<%= link_to 'Send Message', new_conversation_path(:recipient_id => @post.comments.user.id), class: 'send-message-icon' %>

**conversation_controller.rb**
def new
    @user = User.find_by(id: params[:recipient_id])
  end

   def create
    recipients = User.find_by(id: params[:recipient_id])
    conversation = current_user.send_message(recipients, conversation_params[:body], conversation_params[:subject]).conversation
    flash[:success] = "Your message was successfully sent!"
    respond_to do |format|
      format.html {redirect_to conversation_path(conversation)}
      format.js
    end
  end

但是出现以下错误

undefined method `user' for #<Comment::ActiveRecord_Associations_CollectionProxy:0x93b1018>

我正在使用邮箱 gem 来实现消息传递功能。

假设您有一个 comments table,其中有一列 user_id

<% @post.comments.each do |comment| %>
  <%= link_to 'Send Message', new_conversation_path(recipient_id: comment.user_id) %>