Home>

I would appreciate it if you could answer. Thank you!

I want the information to be saved in the intermediate table (group_users) when I create a new group.
user uses devise.

Now, if you enter the required information on the new group creation page and submit it, the information will be saved in the groups table.
However, nothing is saved in the group_users table, which is an intermediate table.
* No error message is displayed.

Corresponding source code
  • routes.rb
Rails.application.routes.draw do
  devise_for: users
  root to: "tweets # index"
  resources: groups, only: [: new,: create]
end
  • migration
class CreateGroups</pre>
<pre><code>class CreateGroupUsers</pre>
<ul>
<li>model</li>
</ul>
<pre><code>class User</pre>
<pre><code>class Group</pre>
<pre><code>class GroupUser</pre>
<ul>
<li>controller</li>
</ul>
<pre><code>class GroupsController</pre>
<ul>
<li>views/groups/new.html.erb</li>
</ul>
<pre><code>
   Create new group 
<% = form_with model: @group, local: true do | f |%>
    
      
      <% = f.label: group name, class:'chat-group-form__label'%>
      
      
      <% = f.text_field: name, class:'chat__group_name chat-group-form__input', placeholder:'Please enter the group name'%>
      
    
    
      
      <% = f.label: Group content, class:'chat-group-form__label'%>
      
      
      <% = f.text_field: content, class:'chat__group_name chat-group-form__input', placeholder:'Please enter the contents of the group'%>
      
    
    
       
      
      <% = f.submit class:'chat-group-form__action-btn'%>
      
    
<% end%>