0

view:

<%= button_to 'Delete Friend', friendships_path(:friend_id => @user), method: 'delete', :form_class => 'delete_btn', remote: true %>

controller:

def destroy
   @return = 'It works!'
   render :json => ActiveSupport::JSON.encode( @return )
end

when i click the button i get a 404 page not found... how can i make the destroy method work for ajax jquery requests?

EDIT:

routes.rb

resources :friendships, :except => [:new, :edit, :update, :index, :show]

running rake:routes

                 friendships POST   /friendships(.:format)                          friendships#create
                  friendship DELETE /friendships/:id(.:format)                      friendships#destroy
2
  • friendships_path doesn't respect REST, what do you have in your routes? Commented Sep 15, 2012 at 21:04
  • @apneadiving i have updated the questions with the routes Commented Sep 15, 2012 at 21:07

1 Answer 1

2

Replace:

friendships_path(:friend_id => @user)

With:

friendship_path(:id => @user)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.