Created
December 12, 2008 11:57
-
-
Save ismasan/35090 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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