Skip to content

Instantly share code, notes, and snippets.

View ekyfauzi's full-sized avatar

Eky Fauzi ekyfauzi

View GitHub Profile
# app/models/post.rb
class Post < ActiveRecord::Base
include Commentable
end
# app/models/concerns/commentable.rb
module Commentable
def self.include(base)
base.class_eval do
has_many :comment, as: :commentable
end
end
def comment_by_user(id)
comments.where(user_id: id)
# app/models/comment.rb
class Comment < ActiveRecord::Base
belongs_to :commentable, polymorphic: true
end
# app/models/image.rb
class Image < ActiveRecord::Base
has_many :comments, as: :commentable
def comment_by_user(id)
comments.where(user_id: id)
end
end
# app/models/post.rb
class Post < ActiveRecord::Base
has_many :comments, as: :commentable
def comment_by_user(id)
comments.where(user_id: id)
end
end
# -*- encoding: utf-8 -*-
require File.expand_path('../lib/coconut/version', __FILE__)
Gem::Specification.new do |gem|
gem.authors = ["Eky Fauzi"]
gem.email = ["ekyfauzi@hotmail.com"]
gem.description = %q{This is my first gem}
gem.summary = %q{I love to code with gem!}
gem.homepage = ""
@ekyfauzi
ekyfauzi / autoheight.js
Last active August 29, 2015 14:19
Autoheight
// Autoheight for element with class .autoheight to be 100% height
$('.autoheight').css({ height: $(window).innerHeight() });
// Auto resize height if window resize
$(window).resize(function(){
$('.autoheight').css({ height: $(window).innerHeight() });
});