SlideShare a Scribd company logo
1 of 21
Download to read offline
Presenting Presenters
        on Rails




                    new bamboo
The Problem
           Either:

Cluttering views with logic.

             or

View logic in business logic.




                                new bamboo
class UsersController
  def show
    @user = User.find(params[:id])
  end
end




<div>
  <% if CONFIG.date_format == :us %>
    <%= @user.created_at.strftime('%m/%d/%y') %>
  <% elsif CONFIG.date_format == :rest_of_the_world %>
    <%= @user.created_at.strftime('%d/%m/%y') %>
  <% end %>
</div>



                                                   new bamboo
class UsersController
  def show
    @user = User.find(params[:id])

    if CONFIG.date_format == :us
      @user_signup_date = @user.created_at.strftime('%m/%d/%y')
    elsif CONFIG.date_format == :rest_of_the_world
      @user_signup_date = @user.created_at.strftime('%d/%m/%y')
    end
  end
end




<div>
  <%= @user_signup_date %>
</div>




                                                         new bamboo
Presenters

Model      Controller   View




                               new bamboo
Presenters

Model      Controller               View




                        Presenter




                                           new bamboo
class UserPresenter
  def initialize(user)
    @user = user
  end
  attr_reader :user

  def signup_date
    if CONFIG.date_format == :us
      self.user.created_at.strftime('%m/%d/%y')
    elsif CONFIG.date_format == :rest_of_the_world
      self.user.created_at.strftime('%d/%m/%y')
    end
  end
end



                                                 new bamboo
class UsersController
  def show
    @user = User.find(params[:id])
    @user_presenter = UserPresenter.new(@user)
  end
end



<div>
  <%= @user_presenter.signup_date %>
</div>




                                                 new bamboo
Disadvantages
• Contrived example
 • move the logic into the model
   • should the model really handle data
      representation
 • move the logic into a helper
  • helpers are ugly
                                           new bamboo
@user_presenter.signup_date

              or

format_date(@user.created_at)




                                new bamboo
Disadvantages
• Accessibility for designers
 • it’s only a convention. Especially if the
    variables are suffixed with “presenter” for
    example.
• Current templating language is Ruby
  anyway.
  • a presenter is just a view without angle
    brackets
                                               new bamboo
My Views on Presenters


• Overkill in most cases.
• Best used in applications, with a lot of
  configuration that governs the view.




                                             new bamboo
Conductors : the Anti-Presenter




 Model       Controller               View




                          Presenter


                                             new bamboo
Conductors : the Anti-Presenter

         Conductor




 Model               Controller               View




                                  Presenter


                                                     new bamboo
Multiple Objects, One
        Form


                    new bamboo
Card
Company               Avatar
           Details




           Update




          User Form

                               new bamboo
One Object, Multiple
     Forms


                       new bamboo
Company




                       Update




Information Form   Change Settings   Change Password


                                              new bamboo
Limitations


• Doesn’t handle has_many associations
 • quite trivial to implement


                                         new bamboo
My Opinions of Conductors

• Extremely useful, in the right situations
 • connecting associated objects
 • DRY’s the controller code
• Potential for abuse
 • probably not worth it if there is only one
    associated model

                                           new bamboo
Notable Mentions
• Blueprint CSS Framework
 • an easy, but pretty demo app
 • http://code.google.com/p/blueprintcss/
• Model - Conductor - Controller (MMC)
 • heavyweight
 • http://mcc.rubyforge.org/svn/trunk/
                                            new bamboo

More Related Content

Similar to Presenting Presenters on Rails

How to disassemble one monster app into an ecosystem of 30
How to disassemble one monster app into an ecosystem of 30How to disassemble one monster app into an ecosystem of 30
How to disassemble one monster app into an ecosystem of 30
fiyuer
 
Resource and view
Resource and viewResource and view
Resource and view
Papp Laszlo
 
Layers of Smalltalk Application
Layers of Smalltalk ApplicationLayers of Smalltalk Application
Layers of Smalltalk Application
speludner
 
Improving software econimics
Improving software econimicsImproving software econimics
Improving software econimics
Kalica Wadhwa
 
modern module development - Ken Barber 2012 Edinburgh Puppet Camp
modern module development - Ken Barber 2012 Edinburgh Puppet Campmodern module development - Ken Barber 2012 Edinburgh Puppet Camp
modern module development - Ken Barber 2012 Edinburgh Puppet Camp
Puppet
 
Medicine For World
Medicine For WorldMedicine For World
Medicine For World
Saifur Rahman
 
AtlasCamp 2013: Confluence patterns
AtlasCamp 2013: Confluence patternsAtlasCamp 2013: Confluence patterns
AtlasCamp 2013: Confluence patterns
colleenfry
 

Similar to Presenting Presenters on Rails (20)

MDC 2022 Practical Blazor.pptx
MDC 2022 Practical Blazor.pptxMDC 2022 Practical Blazor.pptx
MDC 2022 Practical Blazor.pptx
 
2011-02-03 LA RubyConf Rails3 TDD Workshop
2011-02-03 LA RubyConf Rails3 TDD Workshop2011-02-03 LA RubyConf Rails3 TDD Workshop
2011-02-03 LA RubyConf Rails3 TDD Workshop
 
Writing Custom Puppet Types and Providers to Manage Web-Based Applications
Writing Custom Puppet Types and Providers to Manage Web-Based ApplicationsWriting Custom Puppet Types and Providers to Manage Web-Based Applications
Writing Custom Puppet Types and Providers to Manage Web-Based Applications
 
Multi-tenancy with Rails
Multi-tenancy with RailsMulti-tenancy with Rails
Multi-tenancy with Rails
 
A dive into Symfony 4
A dive into Symfony 4A dive into Symfony 4
A dive into Symfony 4
 
How to disassemble one monster app into an ecosystem of 30
How to disassemble one monster app into an ecosystem of 30How to disassemble one monster app into an ecosystem of 30
How to disassemble one monster app into an ecosystem of 30
 
Resource and view
Resource and viewResource and view
Resource and view
 
Layers of Smalltalk Application
Layers of Smalltalk ApplicationLayers of Smalltalk Application
Layers of Smalltalk Application
 
Improving software econimics
Improving software econimicsImproving software econimics
Improving software econimics
 
Rails Plugins - Linux For You, March 2011 Issue
Rails Plugins - Linux For You, March 2011 IssueRails Plugins - Linux For You, March 2011 Issue
Rails Plugins - Linux For You, March 2011 Issue
 
MVVM for Modern Applications
MVVM for Modern ApplicationsMVVM for Modern Applications
MVVM for Modern Applications
 
modern module development - Ken Barber 2012 Edinburgh Puppet Camp
modern module development - Ken Barber 2012 Edinburgh Puppet Campmodern module development - Ken Barber 2012 Edinburgh Puppet Camp
modern module development - Ken Barber 2012 Edinburgh Puppet Camp
 
Ruby For Startups
Ruby For StartupsRuby For Startups
Ruby For Startups
 
Medicine For World
Medicine For WorldMedicine For World
Medicine For World
 
AtlasCamp 2013: Confluence patterns
AtlasCamp 2013: Confluence patternsAtlasCamp 2013: Confluence patterns
AtlasCamp 2013: Confluence patterns
 
WebSphere Portlet Factory: Davalen’s Practical Advice from the Field
WebSphere Portlet Factory: Davalen’s Practical Advice from the Field WebSphere Portlet Factory: Davalen’s Practical Advice from the Field
WebSphere Portlet Factory: Davalen’s Practical Advice from the Field
 
Design Patterns
Design PatternsDesign Patterns
Design Patterns
 
AngularJs Crash Course
AngularJs Crash CourseAngularJs Crash Course
AngularJs Crash Course
 
Rails introduction
Rails introductionRails introduction
Rails introduction
 
Chef vs Puppet vs Ansible vs SaltStack | Configuration Management Tools Compa...
Chef vs Puppet vs Ansible vs SaltStack | Configuration Management Tools Compa...Chef vs Puppet vs Ansible vs SaltStack | Configuration Management Tools Compa...
Chef vs Puppet vs Ansible vs SaltStack | Configuration Management Tools Compa...
 

More from elliando dias

Why you should be excited about ClojureScript
Why you should be excited about ClojureScriptWhy you should be excited about ClojureScript
Why you should be excited about ClojureScript
elliando dias
 
Nomenclatura e peças de container
Nomenclatura  e peças de containerNomenclatura  e peças de container
Nomenclatura e peças de container
elliando dias
 
Polyglot and Poly-paradigm Programming for Better Agility
Polyglot and Poly-paradigm Programming for Better AgilityPolyglot and Poly-paradigm Programming for Better Agility
Polyglot and Poly-paradigm Programming for Better Agility
elliando dias
 
Javascript Libraries
Javascript LibrariesJavascript Libraries
Javascript Libraries
elliando dias
 
How to Make an Eight Bit Computer and Save the World!
How to Make an Eight Bit Computer and Save the World!How to Make an Eight Bit Computer and Save the World!
How to Make an Eight Bit Computer and Save the World!
elliando dias
 
A Practical Guide to Connecting Hardware to the Web
A Practical Guide to Connecting Hardware to the WebA Practical Guide to Connecting Hardware to the Web
A Practical Guide to Connecting Hardware to the Web
elliando dias
 
Introdução ao Arduino
Introdução ao ArduinoIntrodução ao Arduino
Introdução ao Arduino
elliando dias
 
Incanter Data Sorcery
Incanter Data SorceryIncanter Data Sorcery
Incanter Data Sorcery
elliando dias
 
Fab.in.a.box - Fab Academy: Machine Design
Fab.in.a.box - Fab Academy: Machine DesignFab.in.a.box - Fab Academy: Machine Design
Fab.in.a.box - Fab Academy: Machine Design
elliando dias
 
Hadoop - Simple. Scalable.
Hadoop - Simple. Scalable.Hadoop - Simple. Scalable.
Hadoop - Simple. Scalable.
elliando dias
 
Hadoop and Hive Development at Facebook
Hadoop and Hive Development at FacebookHadoop and Hive Development at Facebook
Hadoop and Hive Development at Facebook
elliando dias
 
Multi-core Parallelization in Clojure - a Case Study
Multi-core Parallelization in Clojure - a Case StudyMulti-core Parallelization in Clojure - a Case Study
Multi-core Parallelization in Clojure - a Case Study
elliando dias
 

More from elliando dias (20)

Clojurescript slides
Clojurescript slidesClojurescript slides
Clojurescript slides
 
Why you should be excited about ClojureScript
Why you should be excited about ClojureScriptWhy you should be excited about ClojureScript
Why you should be excited about ClojureScript
 
Functional Programming with Immutable Data Structures
Functional Programming with Immutable Data StructuresFunctional Programming with Immutable Data Structures
Functional Programming with Immutable Data Structures
 
Nomenclatura e peças de container
Nomenclatura  e peças de containerNomenclatura  e peças de container
Nomenclatura e peças de container
 
Geometria Projetiva
Geometria ProjetivaGeometria Projetiva
Geometria Projetiva
 
Polyglot and Poly-paradigm Programming for Better Agility
Polyglot and Poly-paradigm Programming for Better AgilityPolyglot and Poly-paradigm Programming for Better Agility
Polyglot and Poly-paradigm Programming for Better Agility
 
Javascript Libraries
Javascript LibrariesJavascript Libraries
Javascript Libraries
 
How to Make an Eight Bit Computer and Save the World!
How to Make an Eight Bit Computer and Save the World!How to Make an Eight Bit Computer and Save the World!
How to Make an Eight Bit Computer and Save the World!
 
Ragel talk
Ragel talkRagel talk
Ragel talk
 
A Practical Guide to Connecting Hardware to the Web
A Practical Guide to Connecting Hardware to the WebA Practical Guide to Connecting Hardware to the Web
A Practical Guide to Connecting Hardware to the Web
 
Introdução ao Arduino
Introdução ao ArduinoIntrodução ao Arduino
Introdução ao Arduino
 
Minicurso arduino
Minicurso arduinoMinicurso arduino
Minicurso arduino
 
Incanter Data Sorcery
Incanter Data SorceryIncanter Data Sorcery
Incanter Data Sorcery
 
Rango
RangoRango
Rango
 
Fab.in.a.box - Fab Academy: Machine Design
Fab.in.a.box - Fab Academy: Machine DesignFab.in.a.box - Fab Academy: Machine Design
Fab.in.a.box - Fab Academy: Machine Design
 
The Digital Revolution: Machines that makes
The Digital Revolution: Machines that makesThe Digital Revolution: Machines that makes
The Digital Revolution: Machines that makes
 
Hadoop + Clojure
Hadoop + ClojureHadoop + Clojure
Hadoop + Clojure
 
Hadoop - Simple. Scalable.
Hadoop - Simple. Scalable.Hadoop - Simple. Scalable.
Hadoop - Simple. Scalable.
 
Hadoop and Hive Development at Facebook
Hadoop and Hive Development at FacebookHadoop and Hive Development at Facebook
Hadoop and Hive Development at Facebook
 
Multi-core Parallelization in Clojure - a Case Study
Multi-core Parallelization in Clojure - a Case StudyMulti-core Parallelization in Clojure - a Case Study
Multi-core Parallelization in Clojure - a Case Study
 

Recently uploaded

Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
WSO2
 

Recently uploaded (20)

MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectors
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot ModelNavi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu SubbuApidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 

Presenting Presenters on Rails

  • 1. Presenting Presenters on Rails new bamboo
  • 2. The Problem Either: Cluttering views with logic. or View logic in business logic. new bamboo
  • 3. class UsersController def show @user = User.find(params[:id]) end end <div> <% if CONFIG.date_format == :us %> <%= @user.created_at.strftime('%m/%d/%y') %> <% elsif CONFIG.date_format == :rest_of_the_world %> <%= @user.created_at.strftime('%d/%m/%y') %> <% end %> </div> new bamboo
  • 4. class UsersController def show @user = User.find(params[:id]) if CONFIG.date_format == :us @user_signup_date = @user.created_at.strftime('%m/%d/%y') elsif CONFIG.date_format == :rest_of_the_world @user_signup_date = @user.created_at.strftime('%d/%m/%y') end end end <div> <%= @user_signup_date %> </div> new bamboo
  • 5. Presenters Model Controller View new bamboo
  • 6. Presenters Model Controller View Presenter new bamboo
  • 7. class UserPresenter def initialize(user) @user = user end attr_reader :user def signup_date if CONFIG.date_format == :us self.user.created_at.strftime('%m/%d/%y') elsif CONFIG.date_format == :rest_of_the_world self.user.created_at.strftime('%d/%m/%y') end end end new bamboo
  • 8. class UsersController def show @user = User.find(params[:id]) @user_presenter = UserPresenter.new(@user) end end <div> <%= @user_presenter.signup_date %> </div> new bamboo
  • 9. Disadvantages • Contrived example • move the logic into the model • should the model really handle data representation • move the logic into a helper • helpers are ugly new bamboo
  • 10. @user_presenter.signup_date or format_date(@user.created_at) new bamboo
  • 11. Disadvantages • Accessibility for designers • it’s only a convention. Especially if the variables are suffixed with “presenter” for example. • Current templating language is Ruby anyway. • a presenter is just a view without angle brackets new bamboo
  • 12. My Views on Presenters • Overkill in most cases. • Best used in applications, with a lot of configuration that governs the view. new bamboo
  • 13. Conductors : the Anti-Presenter Model Controller View Presenter new bamboo
  • 14. Conductors : the Anti-Presenter Conductor Model Controller View Presenter new bamboo
  • 15. Multiple Objects, One Form new bamboo
  • 16. Card Company Avatar Details Update User Form new bamboo
  • 17. One Object, Multiple Forms new bamboo
  • 18. Company Update Information Form Change Settings Change Password new bamboo
  • 19. Limitations • Doesn’t handle has_many associations • quite trivial to implement new bamboo
  • 20. My Opinions of Conductors • Extremely useful, in the right situations • connecting associated objects • DRY’s the controller code • Potential for abuse • probably not worth it if there is only one associated model new bamboo
  • 21. Notable Mentions • Blueprint CSS Framework • an easy, but pretty demo app • http://code.google.com/p/blueprintcss/ • Model - Conductor - Controller (MMC) • heavyweight • http://mcc.rubyforge.org/svn/trunk/ new bamboo