Ruby practice-helloworld

Source: Internet
Author: User

Development Environment

OS: Windows XP

RUBY: ruby1.9.1

Rails: rails2.3.5

IDE: rubymine2.0.1

 

1. Create a rails Project

 

2. Modify/config/database. yml

In the automatically created Project, the default database is SQLite. If the database is not installed, You need to modify the configuration (MySQL is used in this example)

# MySQL version 5.1.46 <br/> development: <br/> adapter: mysql <br/> Database: Test <br/> Username: Root <br/> password: root <br/> HOST: localhost

 

3. Create a controller

Create say_controller.rb in APP/Controller

 

After the file is created, a series of files created in this process are displayed in the console.

C:/ruby19/bin/ruby.exe-e stdout. sync = true; stderr. sync = true; load ($0 = argv. shift) E:/Ruby/helloworld/script/generate controller-s say
Exists APP/controllers/
Exists APP/helpers/
Create APP/views/say
Exists test/functional/
Create test/unit/helpers/
Create APP/controllers/say_controller.rb
Create test/functional/say_controller_test.rb
Create APP/helpers/say_helper.rb
Create test/unit/helpers/say_helper_test.rb

Process finished with exit code 0

 

4. Modify say_controller.rb

Modify the content as follows:

Class saycontroller <applicationcontroller <br/> def Hello <br/> end

 

5. Create hello. rhtml. ERB

Create hello. rhtml. ERB in the app/views/say directory

 

Modify the content as follows:

<HTML> <br/> <pead> <br/> <title> hello, rails! </Title> <br/> </pead> </P> <p> <body> <br/> <p> hello from rails! </H1> <br/> </body> <br/> </ptml>

 

6. Modify routes. Rb

Modify config/routes. Rb and set new ing rules.

# Route settings. "/say/Hello" indicates the address settings. "controller" indicates the class under the corresponding controllers directory. "action" indicates the method defined in the controller, which is case sensitive. <br/> map. connect '/say/hello',: controller => "say",: Action => "hello" <br/> map. connect ': Controller/: Action/: id' <br/> map. connect ': Controller/: Action/: ID.: format'

 

Start the rails server and run http: // localhost: 3000/say/Hello (case-sensitive)

 

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.