Skip to content

Instantly share code, notes, and snippets.

@bloudermilk
Created January 10, 2013 04:20
Show Gist options
  • Select an option

  • Save bloudermilk/4499445 to your computer and use it in GitHub Desktop.

Select an option

Save bloudermilk/4499445 to your computer and use it in GitHub Desktop.
How I use POROs to build maintainable views
module FieldsetWithSubtext
def fieldset_with_subtext(main_text, subtext, options = {}, &block)
View.new(self, main_text, subtext, options, &block)
end
class View
attr_reader :context, :main_text, :subtext, :options, :block
def initialize(context, main_text, subtext, options = {}, &block)
@context = context
@main_text = main_text
@subtext = subtext
@options = options
@block = block
end
def template
%<%s <small>%s</small>> % contents
end
def contents
[main_text, subtext]
end
def to_s
context.field_set_tag(template.html_safe, options, &block)
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment