2016-09-06 93 views
1

我使用创建一个Rails 4迁移文件:Rails的生成迁移文件支架

rails g migration CreateCompanyAndAttributes 

我编辑的迁移是:

def change 

    create_table :companies do |c| 
    c.integer :name 
    c.string :logo_url 
    c.timestamps 
    end 

    create_table :attributes do |a| 
    a.string :name 
    a.string :description 
    a.string :image 
    a.timestamps 
    end 

    create_table :company_attributes do |t| 
    t.integer :facility_id 
    t.integer :attribute_id 
    t.timestamps 
    end 

end 

现在,我的移民是准备部署,如何我可以立即为所有三个脚手架生成脚手架吗?

我应该先运行:

rake db:migrate 

然后像

rails g scaffold companies 
rails g scaffold attributes 
rails g scaffold companies_attributes 

回答

0

因为我无法从迁移文件中找到对原始问题的答案,所以我最终删除了迁移文件,并为每个表使用单独的rails生成scaffold命令行命令。

rails g scaffold Company name:string logo_url:string 
rails g scaffold Attribute name:string description:string image:string 
rails g scaffold CompanyAttribute company_id:integer attribute_id:integer 
rake db:migrate 
2

看来你想有支架不迁移(你已经这样做手工吧)

您可以使用--skip-migration标志运行scaffold命令。例如:

rails g scaffold Company name:string logo_url:string --skip-migration 

希望它能满足您的需求! :)