mandytrex / workout_buddy

0 stars 0 forks source link

accepting a partner request - AJAX #7

Closed mandytrex closed 9 years ago

mandytrex commented 9 years ago

Currently in my application.js file I have a function that when a user on the partner_requests/show page clicks to Accept a request an AJAX PUT request is fired and the requester_id is saved as the partner_id of the current user. This works.

I am trying to at the same time save the current user's id as the partner_id of the requester. However, all attempts so far have been unsuccessful on this part. Can't get it to work.

First, I tried to set a success function in my ajax request to basically do what the initial ajax request does, but opposite. Then most recently I tried to write a method in my User model that I call in my users_controller under update, but that has failed as well.

I'm wondering if you have any suggestions or notice anything in my code that looks particularly off that could be making this not fully work. Tried to explain the best I can.

If this helps, the files to look at would be: application.js, user model, users_controller, partner_requests/show.html.erb.

@harimohanraj89 @htella @DrRobotmck

harimohanraj89 commented 9 years ago

You're on the right track with writing a model method that will perform this action for you. Here are a couple of thoughts.

def make_partner_request(user_id)
  user = User.find(user_id)
  user.goals.push(self) # You are trying to push a user object into an array of goals
  user.partner.goals.push(self) # You are trying to push a user object into an array of goals
end

Secondly, you have set up a route PUT /users/accept_request, but your AJAX request in application.js is not hitting that route. It is hitting the standard update route. So, I think a good place to start solving this problem would be the following:

harimohanraj89 commented 9 years ago

Closing this now. :+1: