ismasan (owner)

Revisions

gist: 35090 Download_button fork
public
Public Clone URL: git://gist.github.com/35090.git
Embed All Files: show embed
Ruby #
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# 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