[Ruby on Rails] and I learned route map

Source: Internet
Author: User

The previous "[Ruby on Rails] and I learned hello World" mentioned that the route corresponding to the file is CONFIG/ROUTES.RB

In fact, we just added a line of code:

  Resources:p OSTs

However, this code has multiple default routes, which can be viewed through rake routes, as follows:

[Email protected]:/home/ywt/ror_tests/blog# rake routes   Prefix Verb   URI Pattern               controller#action    Posts get    /posts (.: format)          posts#index          POST   /posts (.: format)          posts#create new_post GET    / Posts/new (.: format)      posts#newedit_post get    /posts/:id/edit (.: format) Posts#edit     post get    / Posts/:id (.: format)      posts#show          PATCH  /posts/:id (.: format)      posts#update          PUT    / Posts/:id (.: format)      posts#update          delete/posts/:id (.: format)      Posts#destroy

which

Index corresponds to a list of multiple objects

New New page for a single object

Edit the editing page for a single object

Show a realistic page for a single object

And, Create/update/destroy is not a view (page) file, processing the actual data created, updated, delete operations.

So for a Post object, we have 7 action, four of which have a view file.

Modify the APP/CONTROLLERS/POSTS_CONTROLLER.RB as follows:

Class Postscontroller < Applicationcontroller  def index  end  def new  end  def create  end  def edit  end  def update  end  def show  end  def destroy  EndEnd

Added Files App/views/new.html.erb, App/views/edit.html.erb, App/views/show.html.erb, respectively, corresponding to the new action, edit action, show action.

This chapter lays the groundwork for subsequent work.

[Ruby on Rails] and I learned route map

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.