Skip to content

Instantly share code, notes, and snippets.

@redsquirrel
Created August 25, 2008 11:39
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 redsquirrel/7062 to your computer and use it in GitHub Desktop.
Save redsquirrel/7062 to your computer and use it in GitHub Desktop.
class CarController < ApplicationController
def car
layout = nil
@scripts = []
@stylesheets = []
@car = Car.find(params[:id])
layout = CarPresenter.present(@car, @stylesheets, @scripts)
render :action => find_view, :layout => layout
end
end
class CarPresenter
CAR_VIEWS = {
Toyota => { :layout => "two_column", :stylesheets => ['two_column_layout.css', 'two_column_theme.css'] },
Hyundai => { :layout => "three_column", :stylesheets => ['three_column_layout.css', 'three_column_theme.css'], :scripts => ["discount.js"] }
# etc.
}
def self.present(car, stylesheets, scripts)
car_data = CAR_VIEWS[car.class]
car_data[:stylesheets].each { |css| stylesheets << css }
car_data[:scripts].each { |script| scrits << script }
car_data[:layout]
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment