<%= link_to'消息me!',consectations_path(sender_id:current_user.id,contoctient_id:user.id),方法:' post' post'%>不起作用
我是Rails的新手,并且尝试了太久。我关注的教程为Rails创建简单的聊天功能 https://medium.com/@carly_l/how-to-build-a-simple-chat-chat-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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论