Instantly share code, notes, and snippets.

Embed
What would you like to do?
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_VIEW[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