<%= link_to'消息me!',consectations_path(sender_id:current_user.id,contoctient_id:user.id),方法:' post' post'%>不起作用

发布于 2025-01-20 06:56:44 字数 2107 浏览 1 评论 0原文

我是Rails的新手,并且尝试了太久。我关注的教程为Rails创建简单的聊天功能 https://medium.com/@carly_l/how-to-build-a-simple-chat-c​​hat-messaging-messaging-system-system-in-rails-2958.58efcea047 消息它无法正确布线。

对话.index.html.erb

 <h3>Mailbox</h3>


  <% @conversations.each do |conversation| %>
  
    <% if conversation.sender_id == current_user.id || conversation.recipient_id == current_user.id %>

      <% if conversation.sender_id == current_user.id %>
        <% recipient = User.find(conversation.recipient_id) %>
      <% else %>
        <% recipient = User.find(conversation.sender_id) %>
      <% end %>
      <%= link_to recipient.first_name, conversation_messages_path(conversation)%>
    <% end %>
  <% end %>
</div>
</div>

所有用户

<% @users.each do |user| %>
  <% if user.id != current_user.id %>
  <div class="item">
    <%= user.first_name %> <%= link_to 'Message me!', conversations_path(sender_id: current_user.id, recipient_id: user.id), method: 'post'%>
  </div>
  <% end %>
<% end %>

**对话索引**

  @users = User.all
@conversations = Conversation.all

对话创建功能

def create
byebug
@user = current_user
if Conversation.between(params[:sender_id],params[:recipient_id]).present?
  @conversation = Conversation.between(params[:sender_id], params[:recipient_id]).first
else
  @conversation = Conversation.create!(conversation_params)
end
redirect_to conversation_messages_path(@conversation)
end

** doutes.rb **

  resources :conversations do
     resources :messages
  end

当我单击消息时,我的路径是

http://localhost:3000/conversations?recipient_id=1&sender_id=6

并且什么都不做。

i'm new to rails and trying this for too long. I'm following tutorial to create simple chat feature for rails https://medium.com/@carly_l/how-to-build-a-simple-chat-messaging-system-in-rails-2958efcea047 , and I whenever I click new message it's not routing properly.

conversations.index.html.erb

 <h3>Mailbox</h3>


  <% @conversations.each do |conversation| %>
  
    <% if conversation.sender_id == current_user.id || conversation.recipient_id == current_user.id %>

      <% if conversation.sender_id == current_user.id %>
        <% recipient = User.find(conversation.recipient_id) %>
      <% else %>
        <% recipient = User.find(conversation.sender_id) %>
      <% end %>
      <%= link_to recipient.first_name, conversation_messages_path(conversation)%>
    <% end %>
  <% end %>
</div>
</div>

All Users

<% @users.each do |user| %>
  <% if user.id != current_user.id %>
  <div class="item">
    <%= user.first_name %> <%= link_to 'Message me!', conversations_path(sender_id: current_user.id, recipient_id: user.id), method: 'post'%>
  </div>
  <% end %>
<% end %>

**conversations index **

  @users = User.all
@conversations = Conversation.all

conversations create function

def create
byebug
@user = current_user
if Conversation.between(params[:sender_id],params[:recipient_id]).present?
  @conversation = Conversation.between(params[:sender_id], params[:recipient_id]).first
else
  @conversation = Conversation.create!(conversation_params)
end
redirect_to conversation_messages_path(@conversation)
end

**routes.rb **

  resources :conversations do
     resources :messages
  end

when I click message me path is

http://localhost:3000/conversations?recipient_id=1&sender_id=6

and does nothing.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文