Skip to content

Instantly share code, notes, and snippets.

View pjg's full-sized avatar
💭
Never asked for this.

Paweł Gościcki pjg

💭
Never asked for this.
View GitHub Profile
@pjg
pjg / lyrics.txt
Created April 22, 2012 17:27
Piano Man by Johnny Diggz @ Railsberry
It's 8:00 o'clock on a Friday
The regular crowd shuffles in
there's an old man sitting next to me
making love to his beer
la la di di da
la la di di da
Sing us a song, you're the piano man!
sing us a song tonight
@pjg
pjg / gist:1385392
Created November 22, 2011 10:40
Metaprogramming fu

I have:

def self.host
  @@host ||= something
end

now I want to convert it into this:

def default_url_options(options = {})
# resource hack so that url_for(@post) works like it should
# if a post was given as a parameter to `post_path` it will be assigned to the first (unnassigned) parameter of the route (year)
if options[:controller] == "posts" && options[:year].is_a?(Post)
post = options[:year]
options[:year] = post.year
options.merge(:month => post.month, :slug => post.slug)
else
{}
end
module ActionController
module Resources
class Resource
# Redefining methods from /usr/lib/ruby/gems/1.8/gems/actionpack-2.3.4/lib/action_controller/resources.rb so that the RESTful routes accept member_path option
def member_path
@member_path || options[:member_path] || "#{shallow_path_prefix}/#{path_segment}/:id"
end