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.
Rails.application.routes.draw do devise_for: users root to: "tweets # index" resources: groups, only: [: new,: create] end
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%>
Answer # 1
I edited the create action of the group controller as follows, and it was solved.
I looked it up, tried it, and it worked, but I don't know why.
def create @group = current_user.groups.new (group_params) if current_user.save redirect_to root_path else else render: new end end
- ruby on rails 6 - i want to save data from one form to multiple tables at the same time
- i want to have data for each prefecture with ruby on rails
- ruby on rails - i want to save the purchase information in the db
- ruby - i want to display monthly data in one
- ruby - i want to use two rails renders
- ruby on rails - i want to set responsestatus to 200, but it becomes 401
- ruby on rails - i want to eliminate nomethoderror
- ruby on rails - i want to deploy to aws ec2 server
- ruby - i want to save the prototype and move the page
- ruby on rails - [rails] i want to pass json from controller to html (erb)
- ruby on rails - i want to display a list of liked data
- ruby on rails - i want to erase www on heroku
- ruby on rails - i want to sort the search results
- ruby - i want to save to tave from a site made with rails
- ruby on rails - i want to launch rails with a new file
- ruby on rails - i want to move to the product purchase page
- ruby on rails - no data when using v-if
- ruby on rails - i want to display "sold out" when the product is sold
- python - you may need to restart the kernel to use updated packages error
- php - coincheck api authentication doesn't work
- php - i would like to introduce the coincheck api so that i can make payments with bitcoin on my ec site
- [php] i want to get account information using coincheck api
- the emulator process for avd pixel_2_api_29 was killed occurred when the android studio emulator was started, so i would like to
- python 3x - typeerror: 'method' object is not subscriptable
- i want to call a child component method from a parent in vuejs
- dart - flutter: the instance member'stars' can't be accessed in an initializer error
- xcode - pod install [!] no `podfile 'found in the project directory