[Script _ruby] first Ruby on Rails Web application HelloWorld

Source: Internet
Author: User
Tags ruby on rails

After unremitting efforts to finally put Ruby on Ralis development environment, in the WIN7 system, hurriedly to a most common example to practice practiced hand bar, feel the ruby ...

Again, my ruby-v is ruby-2.0.0p247. Gem-v is: 2.0.3. RAILS-V is: 4.0.0. It should be relatively new! So some commands may not be the same! First, create a new working directory! Mine is: D:\RubyWorkSpace.

Open Ruby's character command interface, go to working directory, new project Hello.

[Plain]View Plaincopyprint?
    1. Rails new Hello

In the old version of Rails Hello, new was introduced in this new version. Because of domestic reasons, the barrier of various walls, so that we may have problems in the new project. If it doesn't go wrong, your project will hear a line of code for the run bundle install after a series of create. Then there is no then, no matter how to wait for others just do not move. This time you need to add some parameters to the new project. As follows:

[Plain]View Plaincopyprint?
    1. Rails new Hello--skip-bundle

This tells rails to skip the bundle installation when creating a new project, and this time see the result, then go into the Hello project to open the Gemfile file, in the first line there is a: source ' https://rubygems.org/' Change to our domestic mirror source:

[Plain]View Plaincopyprint?
    1. SOURCE ' http://ruby.taobao.org/'

There is no problem installing bundles at this time:

[Plain]View Plaincopyprint?
    1. Gem Install bundle

You need to create a new controller: Say Specific action: Hello

[Plain]View Plaincopyprint?
    1. Rails Generate controller Say Hello

The previous version was built with Ruby Script/generate Controller, and after the build succeeds, go to \hello\app\controllers to open the Say_controller.rb file and see the following:

[Ruby]View Plaincopyprint?
    1. Class Saycontroller < Applicationcontroller
    2. def Hello
    3. End
    4. End

Go to: \hello\app\views\say Open edit: Hello.html.erb

[HTML]View Plaincopyprint?
    1. <H1> This is my first Ruby on Rails Web application! </H1>
    2. <p>hello world! </P>

Go to \hello\config Open: routes.rb We will see the route selection in the project:

[HTML]View Plaincopyprint?
    1. Get "Say/hello"

So we can access the controller through the Http://localhost:3000/say/hello to the page.

Other generated js,css files, and so on, not one to say

Start the server:

[Plain]View Plaincopyprint?
    1. Rails Server

Results from last run:

Special Note: If the page appears like this in Chinese, you need to save Hello.html.erb in UTF-8 format, or you will get an error.

[Script _ruby] first Ruby on Rails Web application HelloWorld

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.