ruby on rails - RESTful routing best practice when referencing current_user from route? -
i have typical restful routes user:
/user/:id /user/:id/edit /user/:id/newsfeed
however /user/:id/edit
route can accessed when id equals current_user's id. want current_user have access edit profile. don't want other users able edit profiles don't belong them.
what typically best practice handle situation?
should leave route is, , through error if current_user.id != param[:id]
, forcing front end client calling api track logged in user's id?
should make special route /user/self/edit
, in controller check see if param[:id] == 'self'
?
i would've added special routes current user profile actions, in case don't have check anything. load , display data of current user. example:
/my-profile/edit /my-profile/newsfeed
it's not restful don't have put checks keeping code clean.
if still have have (or want have) strict restful routes use before_filter , check if id = current_user.id. if not return 401 or 403.
Comments
Post a Comment