https://qiita.com/nojinoji/items/2b3f8309a31cc6d88d03
When implementing the DM function using, I want to implement a link that jumps to the chat page other than the user list display page! I think there are many people who have thought.
Therefore, for those who have exchanged DM once, I will try to make it possible to restart chat from the user's My Page as shown in the image below. (Is it an image like LINE's My Page)
I will write a commentary when I feel like it!
view/users/show.html.erb
<% if current_user.id == @user.id %>
<h3>Chat list</h3>
<% @rooms.each do |r| %>
<% r.users.each do |u| %>
<% if u.id == current_user.id %>
<% else %>
<p><a href="/rooms/<%= r.id %>"><%= u.name %>Chat with</a></p>
<% end %>
<% end %>
<% end %>
<% else %>
<% end %>
models/user.rb
has_many :rooms, through: :entries, source: :room
models/room.rb
has_many :users, through: :entries, source: :user
UsersController#show
@rooms = @user.rooms
Recommended Posts