Ruby on Rails command line

Source: Internet
Author: User
Tags ruby on rails

I used IDE development when I learned rails a few days ago. I didn't feel how fast the efficiency of rails is. Today, I tried it through the command line and I was shocked. without writing a line of code, I actually completed a simple model of adding, deleting, modifying, and querying.

 

As follows:

First, configure the environment.

  1. Run the command: rails new blog to create an MVC project structure named "blog.

  2. Rake DB: Create to create a database (use sqllite directly here)

  3. Rails generate controller home index create the controller and index method named home and other struct

  4. Configure the routes. RB route root: 'home # Index' so that the default home page path is home/index.

  5. Then start the rails server command. Access localhost: 3000

  6. You will find the HTML corresponding to the view/home/index.html. ERB File

  7. Rails generate scaffold posts name: String title: String content: string create a structure (including the MVC of this model) where the model is posts Field name, title, and content)

  8. Rake DB: Execute database migration with migrate

  9. Open the view/home/index.html. ERB file and add a line of code <% = link_to 'to posts List page', posts_path %>

  10. Save and exit.

  11. You will be surprised to find that there is no code written, and a posts model with addition, deletion, modification, and query has come out.

 

Of course, this is just a simple model, and the actual production and development will not be so simple, but we can get some inspiration:

Convention is better than Configuration

 

 

This article is from the "Learn Java again" blog, please be sure to keep this source http://3131854.blog.51cto.com/3121854/1550975

Ruby on Rails command line

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.