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)