Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # app/models/post.rb
- class Post < ActiveRecord::Base
- # ASSOCIATIONS
- belongs_to :postable, :polymorphic => true, :counter_cache => true
- end
- # app/models/destination.rb
- class Destination < ActiveRecord::Base
- # ASSOCIATIONS
- has_many :posts, :as => :postable, :dependent => :delete_all
- end
- # migration
- class CreatePosts < ActiveRecord::Migration
- def self.up
- create_table :posts do |t|
- t.string :title
- t.string :permalink
- t.text :content
- t.datetime :activated_at
- t.references :postable, :polymorphic => true # campo polimórfico
- t.references :user
- t.timestamps
- end
- add_index :posts, :permalink
- end
- def self.down
- remove_index :posts, :permalink
- drop_table :posts
- end
- end
Add Comment
Please, Sign In to add comment