Say for instance I have a posts controller that currently has a method user_posts
which shows all of the posts that are associated with the user with the associated id as so:
def user_posts
@user = User.find(params[:id])
@posts = @user.posts.all
end
I want the url to be: foo.com/my_posts
when the posts have the same ID as my current_user; How would I do this? currently my routes are set up as so:
get 'user/posts/:id', to: 'posts#user_posts', as: 'user/posts'
I know that I could create an entirely new controller action for my_posts but I want to know if there is a way to do it in the config/routes.
If for example I am browsing throughout the site and tap on a link that says "user posts" I would expect to go the the users posts and if that user happens to be me I would like the url to show website.com/my_posts