I would be grateful if you could answer! Please! !!Premise/I want to realize
I want to implement it so that I can join a group created by another user by pressing the "Join" button.
I have already implemented it so that the "Join" button is not displayed for the group I created.
# groups/index.html.erb Group list <% @ groups.each do | group |%> <% unless GroupUser.exists? (Group_id: group.id, user_id: current_user.id)%> Join ### I want to implement it so that I can participate by clicking this button <% else%> Participating <% end%> <% = group.name%> <% = group.content%> <% end%>
Rails.application.routes.draw do devise_for: users root to: "tweets # index" resources: groups, only: [: index,: new,: create] end
# groups_controller.rb class GroupsController</pre> <ul> <li>I don't know if it's necessary, but just in case ...</li> </ul> <pre><code data-language = "model">#user class User</pre> <pre><code data-language = "migration">#groups table class CreateGroups</pre> <p>After writing the following code, other users could join an existing group, but the creator of the group left.<br /> I also got the error no template for interactive request ?.</p> <pre><code data-language = "routes">resources: groups, only: [: index,: new,: create] do member do get: join end end
#groups (abridgement) def join @group = Group.find (params [: id]) @ group.users<<current_user @ group.save end (abridgement)
# groups/index.html.erb <% = link_to'join', join_group_path (group)%>
Answer # 1
I was able to resolve myself safely. The reasons and thoughts that the error was resolved are as follows.
・ If you press the join button, an error will occur.
・ When you return to the top page, you can confirm that you are participating.
・ Is it an error because there is no processing after joining?
Adding rediret_to root_path to controller fixed the error!
Rails.application.routes.draw do devise_for: users root to: "tweets # index" resources: groups, only: [: index,: new,: create] do member do get: join end end end
#groups (abridgement) def join @group = Group.find_by (id: params [: id]) if! @ group.users.include? (Current_user) @ group.users<<current_user redirect_to root_path end end (abridgement)
#index Group list <% @ groups.each do | group |%> <% if user_signed_in?%> <% unless GroupUser.exists? (Group_id: group.id, user_id: current_user.id)%> <% = link_to'join', join_group_path (group)%> <% else%> Participating ## Planned to be implemented using link_to so that you can see the details of the group <% end%> <% end%> <% = group.name%> <% = group.content%> <% end%>
- ruby on rails - [rails] post form created with form_with does not work properly
- new project is not created in ruby on rails
- ruby - rails i want to group the same column, link the column name, and click to display all records in that column, but i get a
- ruby on rails - the link between the model created by devise and the model originally created does not work
- ruby on rails - i downgraded the version of the rails app and created it, but puma doesn't install properly
- ruby on rails - i want to jump to the action of another controller with render
- ruby on rails - i want to sort the values of the graph created by gem "chartkick"
- ruby on rails - not created
- ruby on rails - i want to be able to understand the group administrator
- ruby on rails - i'm a beginner i'm deploying an app created with rails on heroku, but i can't proceed with an error
- [ruby on rails] how to write when getting a model nested in multiple stages with includes
- ruby - rails: fattachment_field gives undefined method error
- ruby - i want to output csv with narrowed down conditions with rails
- ruby on rails - the value of find_by (id :) becomes nil
- ruby - unable to save comments in db (rails)
- ruby on rails 5 - the path is changed by redirect_to of rails
- ruby on rails - when i run rails s, i get
- ruby - i want to display specific columns in rails in descending order of numbers
- ruby on rails - description of rails packagejson
- 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