Search code examples
ruby-on-railsindexingroutesrakeposts

rake routes dont show me a posts route


I got my ruby on rails without routes like posts, new, show, edit, create? See code below:

C:\BBJ\myrubyblog2> rake routes
Prefix Verb URI Pattern              Controller#Action
home_index GET /home/index(.:format) home#index
root GET /                           home#index

What does it mean? I don't have any show, posts, new, edit routes, because I didn't create them or are they missing on my rails app folder?

Is there any command that I can run to create each of them?


Solution

  • I think you are looking for resource routing. Resource routing allows you to quickly declare all of the common routes for a given resourceful controller. Instead of declaring separate routes for your index, show, new, edit, create, update and destroy actions, a resourceful route declares them in a single line of code

    resources :posts

    creates seven different routes in your application, all mapping to the posts controller:

    HTTP Verb   Path    Controller#Action   Used for
    GET /posts  posts#index display a list of all posts
    GET /posts/new  posts#new   return an HTML form for creating a new post
    POST    /posts  posts#create    create a new post
    GET /posts/:id  posts#show  display a specific post
    GET /posts/:id/edit posts#edit  return an HTML form for editing a post
    PATCH/PUT   /posts/:id  posts#update    update a specific post
    DELETE  /posts/:id  posts#destroy   delete a specific post
    

    add it your routes.rb file and then hit rake routes in terminal

    For more details on routing you can follow this guide:

    http://guides.rubyonrails.org/routing.html