hi i m new to rails i need to know the => which is the best way to create Database table in Rails?
1)
rails generate model User name:string email:stringthis will create a migration file with something like this
class CreateUsers < ActiveRecord::Migration
def change
create_table :users do |t|
t.string :name # see here name column is already made becoz we have passed a parameters
t.string :email # same as above
t.timestamps
end
end
endthis is one method
2)
rails generate model Pagethis will create a empty migration file something like this
class CreatePages < ActiveRecord::Migration
def change
create_table :users do |t|
===>> now we can add here like t.string "name" to create column manually ========>>>>>
t.timestamps
end
end
endSo which is the good way to do above things example 1 or example 2?
Please tell.
and if i have to write a drop_table method in migration, can i write in the way which i showed below
class CreateSubjects < ActiveRecord::Migration
def change
create_table :subjects do |t|
t.string "name"
t.timestamps
end
end
def self.down
drop_table :subjects
end
end
So again same question
which is the good way to do above things example 1 ( model with parameter ) or example 2 ( model without parameter )?Thanks for Taking Time to Read.