adrianhorning08 / vinyasa

Asana clone. Rails backend, React frontend.
8 stars 3 forks source link

Fetching all the users in a team #8

Closed adrianhorning08 closed 6 years ago

adrianhorning08 commented 6 years ago

Wow, that was difficult. I knew I needed to make an ajax request, so I included the route. Then, through errors, realized I needed a controller. But then I couldn't seem to find get the Users#index to work. I tried to find the team by Team.find(params[:id]), but that didn't work. Finally, this worked:

def index
    team_id = params[:team_id]

   if team_id
     @users = User.includes(:teams).where(teams: {id: team_id})
   else
     @users = User.all
   end
end