在修改完migration后,如果要把development数据库中的结构复制到test数据库中,使用以下命令:
$ rake db:test:clone_structure
sdfs
Wednesday, April 18, 2007
Rake fixture
Labels:
Command,
Convention Mine,
Fixture,
Rake
Rake Migration
在修改完webapp/db/migrate下的rb文件内容后——修改数据库表结构,运行以下命令执行到数据库表中:
$ rake db:migrate
但是我需要先把数据库中的表全部drop掉,然后才能执行这个命令。否则执行了也没有任何效果。在开发webapp的过程中,经常会需要修改数据库表——修改migration文件,有没有更更简便的方法来再次执行migrate的动作?
我要求自己ONLY使用Migration来创建和修改数据库表结构,坚决不再使用SQL语句创建。
Reference:
http://api.rubyonrails.com/classes/ActiveRecord/Migration.html
Thursday, March 15, 2007
irb helps you what?
要开始使用irb,在Windows Command Prompt中只需输入irb,回车便进入irb环境。
比如要列出一个object都具有什么methods,可以这样:
$ irb
irb(main):001:0> puts Object.new.methods.sort
Labels:
Command,
irb,
Ruby Syntax
Thursday, March 08, 2007
Creating Controller with actions
The process for creating a controller is always the same:
$ ruby script/generate controller contollername actionname
This command accomplishes several tasks:
■ It creates a file named app/controllers/controllername_controller.rb.
■ It inserts an empty method definition for the actionname action into that file.
■ It creates a file called app/views/controllername/actionname.rhtml, which will be the file in which you place the ERb template code for this view.
或者先只创建controller以后再创建action:
$ ruby script/generate controller controllername
The majority of controllers correspond directly to an entity model: If there’s a“work” controller, then there’s probably a “work” model.
Labels:
Action,
Command,
Controller,
Rails
Wednesday, March 07, 2007
MySQL Tips
在Windows Command Prompt中
1,登陆MySQL:
$ mysql -u username -p
$ Enter password: ******
2,显示所有数据库:
myslq> show databases;
3,打开数据库:
myslq> use databasename;
4,显示数据库databasename中所有的表:
myslq> use databasename;
myslq> show tables;
5,显示数据库表tablename的信息:
myslq> describe tablename;
Basic Mongrel operation
在Win32上安装Mongrel:
$ gem install win32-service (pick the most recent one)
$ gem install mongrel (pick the win32 pre-built)
$ gem install mongrel_service (Great to run Mongrel as a Windows service)
使用Mongrel运行一个application:
$ cd myrailsapp
$ mongrel_rails start
停止Mongrel运行:
$ mongrel_rails stop
在Windows Command下,用ctrl+c结束。
Labels:
Command,
Environment,
Mongrel,
Setup