Я продолжаю сталкиваться с проблемой при попытке отправить сообщения от одного пользователя другому.Ошибка Form_for в Ruby on Rails
пользователя Модель
has_many :sent_messages, class_name: "Message" , foreign_key: :sender_id
has_many :received_messages, class_name: "Message", foreign_key: :receiver_id
def friendships
Friendship.where("sender_id = ? or receiver_id = ? and status = ?", self.id, self.id, "accepted")
end
def friends
ids = friendships.pluck(:sender_id, :receiver_id).flatten.uniq
ids.delete(self.id)
friends = User.where(id: ids)
end
показать пользователя Просмотр
<% current_user.friends.map do |f| %>
<strong><%= link_to "#{f.name}", conversation_path(f.id) %></strong><p></p>
<% end %>
Диалоги показать View Controller
<% @test.map do |c| %>
<%= c.sender.name %>:
<%= c.message %><p></p>
<% end %>
<%= form_for Message.new do |f| %>
<%= f.text_field :message %>
<%= f.submit %>
<% end %>
Сеансы чата
class ConversationsController < ApplicationController
def show
#current user
#other use in conversation
@other_user = User.find(params[:id])
@test = Message.where("sender_id IN (#{current_user.id},#{@other_user.id}) AND receiver_id IN (#{current_user.id}, #{@other_user.id})")
end
end
сообщений создать контроллер
class MessagesController < ApplicationController
def index
@message = current_user.friends
end
def create
@message = Message.new(params[:message].permit!)
@message.sender_id = current_user.id
@message.receiver_id = User.find(params[:id])
if @message.save
redirect_to :root
end
end
end
Когда я использую form_for в разговорах показывают вид, я получаю «Не удалось найти пользователя без идентификатора» ошибки, хотя я чувствую, что она должна кормить его идентификаторы для обоих пользователей?
Показать ваши маршруты – potashin