Reputation: 11766
I created a Rails 4 migration file using:
rails g migration CreateCompanyAndAttributes
I edited the migration to be:
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
Now that my migration is ready to be deployed, how can I generate scaffold for all three soon to be created tables?
Should I first run:
rake db:migrate
Then something like
rails g scaffold companies
rails g scaffold attributes
rails g scaffold companies_attributes
Upvotes: 1
Views: 1840
Reputation: 11766
Since I was not able to find an answer to my original question starting with a migration file, I ended up deleting the migration file and used separate rails generate scaffold command line commands for each table.
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
Upvotes: 1
Reputation: 1560
It seems that you want to have the scaffold without the migration (you have already done it manually)
You can run the scaffold command with Use the --skip-migration flag. For example:
rails g scaffold Company name:string logo_url:string --skip-migration
Hope it meets your need! :)
Upvotes: 3