Skip to content

Instantly share code, notes, and snippets.

@tdantas
Created September 7, 2013 18:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tdantas/6477941 to your computer and use it in GitHub Desktop.
Save tdantas/6477941 to your computer and use it in GitHub Desktop.
Using Pure ERB
require 'erb'
class ERBPrivateClass
def self.build
new('Joao', 'Almeida')
end
attr_accessor :first_name, :last_name
def initialize(first, last)
@first_name = first
@last_name = last
end
def full_name
"#{first_name} #{last_name}"
end
end
class ERBPrivateClasssView
def self.template
<<-XXX
<html>
<%= partial "thiago teixeira dantas" %>
<%= @variable.full_name %>
</html>
XXX
end
end
class ApplicationController
def partial(name)
"#{name}_jony"
end
def render(template)
compiled = ERB.new(template)
compiled.result(binding)
end
end
class ERBPrivateClasssController < ApplicationController
def index
@variable = ERBPrivateClass.build
render ERBPrivateClasssView.template
end
end
puts ERBPrivateClasssController.new.index
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment