亚洲av成人无遮挡网站在线观看,少妇性bbb搡bbb爽爽爽,亚洲av日韩精品久久久久久,兔费看少妇性l交大片免费,无码少妇一区二区三区

  免費注冊 查看新帖 |

Chinaunix

  平臺 論壇 博客 文庫
最近訪問板塊 發(fā)新帖
查看: 56326 | 回復: 0
打印 上一主題 下一主題

Ruby on Rails 常用命令總結 [復制鏈接]

論壇徽章:
0
跳轉到指定樓層
1 [收藏(0)] [報告]
發(fā)表于 2016-03-22 14:19 |只看該作者 |倒序瀏覽
##在已有數(shù)據(jù)模型的基礎上添加字段 新建遷移文件
     rails generate migration add_quantity_to_line_items quantity:integer
     rails generate migration remove_quantity_from_line_items quantity:integer

##創(chuàng)建控制器   
     rails generate controller 單數(shù)形式的類名  方法名

##Rails腳手架創(chuàng)建
     rails generate scaffold line_item(類名) product:integer(屬性及屬性的類型)

##查詢安裝的所有Rails版本
gem list --local rails

##使用指定的Rails版本創(chuàng)建工程
rails _3.2.9_ new app_name

##創(chuàng)建模型文件
rails generate model Article title:string text:text

##創(chuàng)建JoinTable,創(chuàng)建聯(lián)合數(shù)據(jù)表
rails g migration CreateJoinTableCustomerProduct customer product

生成的遷移如下:
class CreateJoinTableCustomerProduct < ActiveRecord::Migration
  def change
    create_join_table :customers, :products do |t|
      # t.index [:customer_id, :product_id]
      # t.index [:product_id, :customer_id]
    end
  end
end

##支持的類型修飾符
在字段類型后面,可以在花括號中添加選項?捎玫男揎椃缦拢

limit:設置 string/text/binary/integer 類型字段的最大值;
precision:設置 decimal 類型字段的精度,即數(shù)字的位數(shù);
scale:設置 decimal 類型字段小數(shù)點后的數(shù)字位數(shù);
polymorphic:為 belongs_to 關聯(lián)添加 type 字段;
null:是否允許該字段的值為 NULL;
例如,執(zhí)行下面的命令:

$ rails generate migration AddDetailsToProducts 'price:decimal{5,2}' supplier:references{polymorphic}
生成的遷移如下:

class AddDetailsToProducts < ActiveRecord::Migration
  def change
    add_column :products, :price, :decimal, precision: 5, scale: 2
    add_reference :products, :supplier, polymorphic: true, index: true
  end
end
您需要登錄后才可以回帖 登錄 | 注冊

本版積分規(guī)則 發(fā)表回復

  

北京盛拓優(yōu)訊信息技術有限公司. 版權所有 京ICP備16024965號-6 北京市公安局海淀分局網(wǎng)監(jiān)中心備案編號:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年舉報專區(qū)
中國互聯(lián)網(wǎng)協(xié)會會員  聯(lián)系我們:huangweiwei@itpub.net
感謝所有關心和支持過ChinaUnix的朋友們 轉載本站內(nèi)容請注明原作者名及出處

清除 Cookies - ChinaUnix - Archiver - WAP - TOP