Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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
Add Comment
Please, Sign In to add comment