[Rails] Display people who have DMed on My Page so that you can link to the chat page! 【memorandum】

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

[Rails] Display people who have DMed on My Page so that you can link to the chat page! 【memorandum】
[Ruby On Rails] Description that allows only specific users to transition to the edit page
Now that you have deployed AWS with Rails On Docker, let's organize the contents.
[Ruby on Rails] Only the user who posted can edit
[Ruby on Rails] Quickly display the page title in the browser
(Ruby on Rails6) Display of the database that got the id of the database
[PostgreSQL] The story that you have to cut the session properly
The first thing to do before you can use Rails6 Ajax