I believe that for your case you can use the concept of Nested Resources
.
Basically in your routes.rb
you will do something like:
resources :blogs do
resources :posts
end
This will create routes like:
blog_posts GET /blogs/:blog_id/posts(.:format) posts#index
POST /blogs/:blog_id/posts(.:format) posts#create
new_blog_post GET /blogs/:blog_id/posts/new(.:format) posts#new
edit_blog_post GET /blogs/:blog_id/posts/:id/edit(.:format) posts#edit
blog_post GET /blogs/:blog_id/posts/:id(.:format) posts#show
PATCH /blogs/:blog_id/posts/:id(.:format) posts#update
PUT /blogs/:blog_id/posts/:id(.:format) posts#update
DELETE /blogs/:blog_id/posts/:id(.:format)
So you'll always have the blog ID as a reference in your accounts.
Warning Note that the helpers
of urls
will also change, post_path
to blog_post_path
for example always passing the blog reference as blog_post_path(@blog)
.