+ Taste Cookie Of Ruby on Rails +

本文介绍了作者初次接触 Ruby on Rails 的过程,包括在 Windows 下安装 Ruby 和 Rails、创建项目和控制器、配置数据库等步骤,并演示了如何通过简单的代码实现 CRUD 操作。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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 ... ... ...

 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值