Change route path in Rails -


i have resource change path of.

resources :blog_posts 

that makes path localhost:3000/blog_posts/:id

how make instead of having "blog_posts" in front of it, id comes right after, this? localhost:3000/:id

i'm guessing there's way make dynamic, don't have get every new blog post.

answer

get '/:id', to: 'blog_posts#show', as: :show_blog_post

you need as: :show_blog_post because prefix won't there. example, you'll able call show_blog_post_path(@blog_post)

you can define route like: get '/:id', to: 'blog_posts#show'


Comments

Popular posts from this blog

javascript - Google App Script ContentService downloadAsFile not working -

javascript - Function overwritting -

c# - Exception when attempting to modify Dictionary -