routing - Change Rails namespaced route to personalized params route -
tl;dr: want have username621/posts/title-of-post
instead of member/posts/1
the changing of post id
post title
easy enough since used freindly_id
gem generate slugs.
however, having difficulty routing personalized params route instead of current namespaced route. here current routing:
namespace :member resources :posts end
i want replace member
namespace user's username
. if username user123
, route should user123/posts/title-of-post
.
i think not standard rails routing , tried looking similar questions no results.
for more complicated routes.rb
, add path
option
namespace :member, path: ":user_id" resources :posts end
should want, e.g. http://localhost:3000/621/posts/1
then have add friendly_id user
, post
have become http://localhost:3000/username621/posts/title-of-post
however, you'll need pore through codebase things member_post_path(post)
, change member_post_path(post.user, post)
Comments
Post a Comment