kurenn / market_place_api

The API on Rails tutorial application
142 stars 68 forks source link

Don't set the user_id manually #46

Open ACPK opened 9 years ago

ACPK commented 9 years ago

In Chapter 6, you set the user_id manually.

 post :create, { user_id: user.id, product: @product_attributes }

This should automatically be set using the current_user attribute in the controller.

kurenn commented 9 years ago

It is actually being done like that, https://github.com/kurenn/market_place_api/blob/chapter7/app/controllers/api/v1/products_controller.rb

We need to send the user_id because of the nesting of resources, it is an issue more related to an interface from the outside...

What do you think?

ACPK commented 9 years ago

In the spec, you have (example delete action):

  delete :destroy, { user_id: @user.id, id: @product.id }

Using Devise_token_auth, I have refactored the above code to the snippit below as the access-token, client, uid, and expiration date are in the header.

  delete :destroy, { id: @product.id }
kurenn commented 9 years ago

And did you updated your routes file?