+ Taste Cookie Of Ruby on Rails +

来源:互联网 发布:c多进程编程 编辑:程序博客网 时间:2024/05/19 02:21

This logs includes some details about my first taste of Ruby on Rails:

1. Install Ruby in windows (Of course MySql has also been installed).

2. Install Rails by Gem.
> gem install rails --remote

3. Create New Project.
> cd c:
> rails myrails

4. Create New Action.
> ruby scriptgenerate controller test

5. Write in appcontrollertest_controller.rb:

class TestController < ApplicationController
def index
render_text "Hello, Welcome to Ruby World!"
end
end

6. Open http://127.0.0.1:3000/test/ . You will find the world was printed out.

7. Database Configure.
Create the database named myrails and create a table named user.
To tell Rails how to find the database, edit the file c:myrailsconfigdatabase.yml
Set database name, username and password.
Restart the script/server.

8. Create New Modules and New TableControllers.
> ruby scriptgenerate model user
> ruby scriptgenerate controller user
Just not do any change to appmodelsuser.rb but write in appcontrolleruser_controller.rb:

class UserController < ApplicationController
def index
scaffold :user
end
end

This single line of code will bring the database table to life. It defines actions for all CRUD operations,
immediately allowing us to create, read, update, and delete recipes in our database!

To be continued ... ... ...

 
原创粉丝点击