kurenn / market_place_api

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

Don't set the user_id manually #46

Open ACPK opened 8 years ago

ACPK commented 8 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 8 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 8 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 8 years ago

And did you updated your routes file?