Start Ruby on Rails development experience (1)

Source: Internet
Author: User

At first, I saw a lot of attractive applications about Ruby on Rails. Like many more eager programmers, I learned Ruby syntax and plunged into the beautiful palace of Rails, experience the sense of accomplishment of rapid Web application development, but I have to always be confused by lack of in-depth understanding of the Ruby language: Why does this class have nothing to do? Why does it work? What does the code written in that place mean? What is the hierarchy of so many files?

BKJIA-related articles: What are the core features of Ruby on Rails?

After the initial stages of Ruby language confusion. start using it slowly. it is not difficult to learn one thing as long as you settle your mind. ruby will be used initially, but this is only a language. you can't take the language into full swing every day. You should also do the work at the application level. when I see a large number of cases submitted in the Rails community every day, I can't help but experience the pleasure, so I have been planning to write Ruby on Rails about rapid Web development and application. I can't take any time to calm down and try to use it.

Of course, for Ruby and Ruby on Rails Applications, I have not been in touch for a long time. We can only gradually explore and move forward with a beginner's attitude of exploration, which is only known to myself. Therefore, there will inevitably be a lot of misunderstandings and deviations, and we hope you will be able to accept your patience. After talking about the Ruby experience, let's get started. Apply the classic instance Hello World!

Preparations

<1> a preliminary understanding of Ruby and Ruby on Rails.

If you don't know what Ruby is, why? Please refer to BKJIA's previous articles on Ruby on Rails getting started and entering the Ruby on Rails world.

<2> build a Ruby on Rails development environment.

For details about how to build a Ruby on Rails development environment and install Ruby on Rails, refer to the most detailed steps for installing Ruby on Rails.

Go to development

<1> confirm the development environment version

Before entering this stage, confirm that your Ruby on Rails development environment has been set up. After confirming that the environment has been installed, confirm that the Ruby and Rails mines have their own versions. The instance Development Environment version is as follows:

◆ Ruby Version: 1.8.6.

◆ Rails Version: 2.3.5.

◆ Operator System: Windows 7.

Rails is still developing rapidly. Although the version is somewhat outdated, it does not prevent us from playing this Rails framework application.

<2> create the first application

After installing the Rails framework, you can also get a new command line in the application: Rails. similar to using Rails-v in Cmd, you can view the current Rails version. This command line tool helps you build a new Rails Application. when we are about to create a Rails Application. you will certainly ask what compilation tool is used? This issue is currently available here.

A Rails command line is added after the Rails framework is installed. the Rails command line can be used in background operations to create and run an application with minimal configuration. to make Rails background operations work, Rails must find various components of the application. (that is, the directory structure of the application ). this means you must Create a fixed directory structure and place our code in the correct directory for calling. These directory structures are created by default in Create new Rails Application. create a Rails Application. make sure that he has a working directory: C: \ User \ Chenkai \ WorkDemo named myfirstdemo. Open Cmd. enter the working directory and enter rails myfirstdemo.

After the automatic creation is complete, note that the hard disk address I created is under the directory C: \ User \ Chenkai \ WorkDemo. Make sure the myfirtdemo folder exists. Otherwise, the source file will be overwritten to check the directory structure:

Creating a directory structure is clear at a glance. don't worry about these directories for the moment. currently, I only need to use one of them, that is, the Public directory. as the name suggests, this directory file is finally exposed to users. there are several key files: Dispatcher [distributor]. dispatcher. cgi, dispatch. fcgi, and dispatch. rb [ruby file]. the distributor is mainly responsible for receiving browser requests from users and directing these requests to the specified application code. A bit similar to Control.

Create MyfirstDemo on the hard disk and we can see a Script Folder:

This directory stores some tool scripts, which will be used in the development program. Now we use one of the Server scripts. it starts a standalone WebBrick server [A Wbe server written in Ruby]. the newly created Rails Application runs in it and starts WebBrick:

We can see from the prompt that a WebBrick server is created on port 3000. Let's open http: // localhost: 3000/to see the effect:

Currently, this rails Application runs without self-coding content. Next, add a Hello World! To the program. Before adding, I want to talk about the entire Hello World output process, which is actually the process of the MVC framework:


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.