Rails OO views
-
Upload
elia-schito -
Category
Technology
-
view
3.346 -
download
0
description
Transcript of Rails OO views
Loading...
Markdown vs. MongoDBA Journey through bleeding edge
technologies for the NeXT Web
RubyMotion vs. BackboneA Journey through bleeding edge
technologies for the NeXT Web
Rails Views for the
OO-savvy Rubyist
M
V
C
M
V
C
Look at: Rails current implementation
def show @post = Post.find(params[:id]) @title = @post.titleend
<h1><%= @post.title %></h1><p><%= @post.body %></p>
<html> <head><title><%= @title %></title></head> <body><%= yield %></body></html>
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.
And tell me boy, what‘s wrong with my @ivars
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
I‘ll stick with "helper_method".
Give me some "decent_exposure"?
It‘s "obviews"!
I‘m made of rubber, you‘re made of glue.
And tell me boy, what ya doing about this?
helper_methodpros: rails standardcons: verbose, bad semantics, class level
helper_methodpros: rails standardcons: verbose, bad semantics, class level
helper_methodpros: rails standardcons: verbose, bad semantics, class level
decent_exposurepros: easy syntax, good defaultscons: class level
decent_exposurepros: easy syntax, good defaultscons: class level
decent_exposurepros: easy syntax, good defaultscons: class level
obviewspros: easy syntax, action levelcons: unpublished
obviewspros: easy syntax, action levelcons: unpublished
obviewspros: easy syntax, action levelcons: unpublished!
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><%= post.title %></h1>
<p><%= post.body %></p>
We want examples!
Obviews
Obviews
on rubygems shipping today!
Thank you !1
No monkeys were harmed during the making of this keynote
twitter: @eliagithub: @eliablog: dev.mikamai.comblog: elia.schito.me
MIKAMAI
No monkeys were harmed during the making of this keynote
twitter: @eliagithub: @eliablog: dev.mikamai.comblog: elia.schito.me
MIKAMAI