Loading...
Markdown vs. MongoDB
 A Journey through bleeding edge
          technologies
        for the NeXT Web
RubyMotion vs. Backbone
 A Journey through bleeding edge
          technologies
        for the NeXT Web
Rails Views
     for the
OO-savvy Rubyist
M

        V




    C
V




C
Look at: Rails current implementation
def show
 @post = Post.find(params[:id])
 @title = @post.title
end
<h1><%= @post.title %></h1>
<p><%= @post.body %></p>
<html>
 <head><title><%= @title %></title></head>
 <body><%= yield %></body>
</html>
And tell me boy, what‘s wrong
                    with my @ivars




My name‘s Guybrush threepwood.     I‘m new in town
Matz told me their only for Object‘s internal state
Who‘s in charge here?
Nice talking to you.
So how should
I use @ivars?
When you design a class, you decide
what internal state it has and also
decide how that state is to appear on
the outside (to users of your class).
The internal state is held in instance
variables. The external state is
exposed through methods we‘re call-
ing attributes.
Dave Thomas,
Programming Ruby
Deep in the Rails source...
# Define some internal variables that
# should not be propagated to the view.
self.protected_instance_variables = [
  :@_status, :@_headers, :@_params, :@_env,
  :@_response, :@_request, :@_view_runtime,
  :@_stream, :@_url_options, :@_action_has_layout
]
# Define some internal variables that
# should not be propagated to the view.
self.protected_instance_variables = [
  :@_status, :@_headers, :@_params, :@_env,
  :@_response, :@_request, :@_view_runtime,
  :@_stream, :@_url_options, :@_action_has_layout
]
protected instance variables
protected - instance - variables
And tell me boy, what ya
                 doing about this?




I‘ll stick with "helper_method".
Give me some "decent_exposure"?
It‘s "obviews"!
I‘m made of rubber, you‘re made of glue.
helper_method
pros: rails standard
cons: verbose, bad semantics,
class level
helper_method
pros: rails standard
cons: verbose, bad semantics,
class level
helper_method
pros: rails standard
cons: verbose, bad semantics,
class level
decent_exposure
pros: easy syntax, good defaults
cons: class level
decent_exposure
pros: easy syntax, good defaults
cons: class level
decent_exposure
pros: easy syntax, good defaults
cons: class level
obviews
pros: easy syntax, action level
cons: unpublished
obviews
pros: easy syntax, action level
cons: unpublished
obviews
pros: easy syntax, action level
cons: unpublished!
We want examples!
We want examples!




class PostsController < ApplicationController
 expose :posts
 def posts; Post.all; end
end
We want examples!




def show
 expose post
end
def post; posts.find(params[:id]) end
We want examples!




def show
 expose post: posts.find(params[:id])
end
We want examples!




<h1><%= pos title %></h1>
           t.
<p><%= post.body %></p>
Obviews
Obviews
on rubygems shipping today!
Thank you !1
twitter:   @elia
github:    @elia
blog:      dev.mikamai.com
blog:      elia.schito.me


                     MIKAMAI


 No monkeys were harmed during
    the making of this keynote
twitter:   @elia
github:    @elia
blog:      dev.mikamai.com
blog:      elia.schito.me


                     MIKAMAI


 No monkeys were harmed during
    the making of this keynote

Rails OO views