Skip to content

Instantly share code, notes, and snippets.

View bansalakhil's full-sized avatar

Akhil Bansal bansalakhil

View GitHub Profile
@bansalakhil
bansalakhil / gist:3401574
Created August 20, 2012 06:34
Edge Rails accepts a polymorphic modifier for references in migration generators
Allow scaffold/model/migration generators to accept a polymorphic modifier for references/belongs_to, for instance
rails g model Product supplier:references{polymorphic}
will generate the model with belongs_to :supplier, polymorphic: true association and appropriate migration.
@bansalakhil
bansalakhil / gist:3207071
Created July 30, 2012 13:59
Custom Flash Types in Edge Rails
# Rails Edge: Custom Flash Types
#
#Rails just got some syntactic sugar for dealing with flash messages in
#your controllers and views.
#
#You can now declare the following in your controllers:
#
class ApplicationController
add_flash_types :error, :warning
@bansalakhil
bansalakhil / gist:3205304
Created July 30, 2012 06:24
Git log searching
Only show commit history earlier than 5 days ago:
git log --since=5.day.ago
Only show commit history older than 5 days ago:
git log --until=5.day.ago
@bansalakhil
bansalakhil / gist:3181222
Created July 26, 2012 09:34
Calculating Sum
# I have seen people writing something like:
users.collect{|u| u.tasks.size}.sum
# This can also be written as
users.sum{|u| u.tasks.size}