app/config/routes.rb
scope path: '/:name' do
resources :posts, only: [:show]
end
resources :posts, except: [:show]
This will pass the :name
and :id
params into your posts#show
function.
app/controllers/posts_controller.rb
def show
user = User.where(name: params[:name]).first
@post = Post.where(['id = ? AND user_id = ?', params[:id], user.id])
render @post
end
NOTE: This can be more Rails 4 friendly by using Strong Parameters.