Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Ruby on Rails Presenters

Jon Canady
January 16, 2012

Ruby on Rails Presenters

Slides that helped introduce the discussion about using Presenters to clean up Controller/View interaction @ Columbus Ruby Brigade (http://columbusrb.com)

Jon Canady

January 16, 2012
Tweet

More Decks by Jon Canady

Other Decks in Programming

Transcript

  1. app/presenters/list_presenter.rb 1 class ListPresenter 2 attr_accessor :drugs, :plan, :user, :member

    3 attr_accessor :ui_flag_1, :ui_flag_2 4 5 def initialize(opts = {}) 6 @drugs = opts.fetch(:drugs) { [] } 7 @plan = opts.fetch(:plan) 8 @user = opts.fetch(:user) { nil } 9 @member = opts.fetch(:member) { nil } 10 @ui_flag_1 = opts.fetch(:ui_flag_1) { false } 11 @ui_flag_2 = opts.fetch(:ui_flag_2) { true } 12 end 13 14 def each(&block) 15 @drugs.each(&block) 16 end 17 18 end
  2. app/controllers/list_controller.rb 1 class ListController < ApplicationController 2 before_filter :set_plan, :set_drugs,

    :set_member 3 4 def show 5 @view = ListPresenter.new( 6 :drugs => @drugs, 7 :plan => @plan, 8 :user => current_user, 9 :member => @member, 10 :ui_flag_1 => params[:ui_flag_1] 11 ) 12 end 13 14 end