Created
September 4, 2017 02:49
-
-
Save willnet/45900989357385e44e6ea97ea43ec901 to your computer and use it in GitHub Desktop.
rails template for polymorphic association
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
generate(:model, 'article') | |
generate(:model, 'event') | |
generate(:model, 'comment commentable:references{polymorphic}:index') | |
rake('db:migrate') | |
insert_into_file 'app/models/article.rb', "has_many :comments, as: :commentable\n", after: "class Article < ApplicationRecord\n" | |
insert_into_file 'app/models/event.rb', "has_many :comments, as: :commentable\n", after: "class Event < ApplicationRecord\n" | |
create_file 'db/seeds.rb' do | |
<<~SEED | |
article = Article.create! | |
article.comments.create! | |
event = Event.create! | |
event.comments.create! | |
SEED | |
end | |
rake('db:seed') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment