在RUBY学习中已经说了在ruby中合法的字段类型有以下这些: binary, boolean, date, datetime, decimal, float, integer, string, time, 以及 timestamp。
在ruby中:
decimal映射成:
[quote] t.column:price,:decimal,:precision=>10,:scale=>2,:null=>false[/quote]
在ruby2.0以后的版本中使用scaffold建立脚手架用
[quote]ruby script/generate scaffold ModelName field:type field:type field:type[/quote]
如:
运行之后会在你的项目中的app/controllers中产生一个ProductsController的控制器,
在app/views中产生一个products的文件夹,里面包括edit.html.erb,index.html.erb,new.html.erb,show.html.erb四个文件。
在ProductsController的控制器中一共包括index,show,new,edit,create,update,destroy五个方法,分别代表5个动作。
进入你的项目根目录,运行
[quote]ruby script/server[/quote]
启动服务.
在浏览器中键入[url]http://127.0.0.1:3000/products[/url]
好了,一个增删查改的操作已经完成。
在ruby中:
decimal映射成:
[quote] t.column:price,:decimal,:precision=>10,:scale=>2,:null=>false[/quote]
在ruby2.0以后的版本中使用scaffold建立脚手架用
[quote]ruby script/generate scaffold ModelName field:type field:type field:type[/quote]
如:
ruby script/generate scaffold Product title:string description:string img_url:string price:decimal
运行之后会在你的项目中的app/controllers中产生一个ProductsController的控制器,
在app/views中产生一个products的文件夹,里面包括edit.html.erb,index.html.erb,new.html.erb,show.html.erb四个文件。
在ProductsController的控制器中一共包括index,show,new,edit,create,update,destroy五个方法,分别代表5个动作。
进入你的项目根目录,运行
[quote]ruby script/server[/quote]
启动服务.
在浏览器中键入[url]http://127.0.0.1:3000/products[/url]
好了,一个增删查改的操作已经完成。