This generates the model. Unlike rails generate resource ResourceName
, this
only generates the model, database migration and tests.
$ rails generate model genre
invoke active_record
create db/migrate/20130322105853_create_genres.rb
create app/models/genre.rb
invoke test_unit
create test/unit/genre_test.rb
invoke factory_girl
create test/factories/genres.rb
After creating the database migration in ``, running migration will update the
database and schema.rb
.
$ rake db:migrate
== CreateGenres: migrating ===================================================
-- create_table(:genres)
-> 0.0310s
== CreateGenres: migrated (0.0310s) ==========================================
Seed the databaase to initialize it with some default values.
$ rake db:seed
Generate a migration file. This will be then edited to modify Movie with an additional column to connect to Genre
$ rails generate migration AddGenreToMovie
invoke active_record
create db/migrate/20130322114045_add_genre_to_movie.rb
Apply the update to movies by running rake db:migreate
$ rake db:migrate
== AddGenreToMovie: migrating ================================================
-- add_column(:movies, :genre_id, :integer)
-> 0.0006s
-- add_index(:movies, :genre_id)
-> 0.0006s
== AddGenreToMovie: migrated (0.0013s) =======================================
Create a migration that will be used for the join table.
$ rails g migration CreateMovieGenreJoin
invoke active_record
create db/migrate/20130322124335_create_movie_genre_join.rb
$ rake db:migrate
== CreateMovieGenreJoin: migrating ===========================================
-- create_table(:genre_movie, {:id=>false})
-> 0.0335s
== CreateMovieGenreJoin: migrated (0.0336s) ==================================
$ rails g migration DropGenreFromMovies
invoke active_record
create db/migrate/20130322125010_drop_genre_from_movies.rb
$ rake db:migrate
== DropGenreFromMovies: migrating ============================================
-- remove_column(:movies, :genre_id)
-> 0.0885s
== DropGenreFromMovies: migrated (0.2793s) ===================================
$ rails g model Person
invoke active_record
create db/migrate/20130322132531_create_people.rb
create app/models/person.rb
invoke test_unit
create test/unit/person_test.rb
invoke factory_girl
create test/factories/people.rb
$ rails g migration AddDirectorToMovie
invoke active_record
create db/migrate/20130322133252_add_director_to_movie.rb
$ rake db:migrate
== CreatePeople: migrating ===================================================
-- create_table(:people)
-> 0.0320s
== CreatePeople: migrated (0.0321s) ==========================================
== AddDirectorToMovie: migrating =============================================
-- add_column(:movies, :director_id, :integer)
-> 0.0006s
== AddDirectorToMovie: migrated (0.0007s) ====================================
$ rails g model Role
invoke active_record
create db/migrate/20130322135917_create_roles.rb
create app/models/role.rb
invoke test_unit
create test/unit/role_test.rb
invoke factory_girl
create test/factories/roles.rb
$ rails g model Role
invoke active_record
create db/migrate/20130322135917_create_roles.rb
create app/models/role.rb
invoke test_unit
create test/unit/role_test.rb
invoke factory_girl
create test/factories/roles.rb
$ rake db:migrate
== CreateRoles: migrating ====================================================
-- create_table(:roles)
-> 0.0335s
== CreateRoles: migrated (0.0336s) ===========================================
$ rails g migration DropDirectorFromMovie
invoke active_record
create db/migrate/20130322140228_drop_director_from_movie.rb
$ rake db:migrate
== DropDirectorFromMovies: migrating ==========================================
-- remove_column(:movies, :director_id)
-> 0.0885s
== DropDirectorFromMovies: migrated (0.2793s) =================================