Skip to content

Instantly share code, notes, and snippets.

@ismasan
Created December 12, 2008 11:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ismasan/35090 to your computer and use it in GitHub Desktop.
Save ismasan/35090 to your computer and use it in GitHub Desktop.
# this facades a model with all helpers and controller data available
#
class RssModel
def initialize(model, request, controller)
@model, @request, @controller = model, request, controller
end
# you have request available as well
#
def url
product_url(@model) # this includes the host
end
# this allows us to call all helper and controller methods transparently
#
def method_missing(method_name, params, &block)
@controller.send(method_name,*params, &block)
end
end
# you use it like this in a controller
#
class ProductsController < ApplicationController
def some_method
@collection = Product.recent(15).collect{|model| RssModel.new(model, request, self)}
render some_rss_template
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment