Presenting Presenters on Rails

Loading...

Flash Player 9 (or above) is needed to view presentations.
We have detected that you do not have it on your computer. To install it, go here.

0 comments

Post a comment

    Post a comment
    Embed Video
    Edit your comment Cancel

    1 Favorite

    Presenting Presenters on Rails - Presentation Transcript

    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
    SlideShare Zeitgeist 2009

    + adorepumpadorepump Nominate

    custom

    107 views, 1 favs, 0 embeds more stats

    More info about this document

    © All Rights Reserved

    Go to text version

    • Total Views 107
      • 107 on SlideShare
      • 0 from embeds
    • Comments 0
    • Favorites 1
    • Downloads 0
    Most viewed embeds

    more

    All embeds

    less

    Flagged as inappropriate Flag as inappropriate
    Flag as inappropriate

    Select your reason for flagging this presentation as inappropriate. If needed, use the feedback form to let us know more details.

    Cancel
    File a copyright complaint
    Having problems? Go to our helpdesk?

    Categories

    Tags