<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
  <channel>
    <link>http://persumi.com/u/fredwu/tech/e/blog/t/buffer</link>
    <generator>Persumi - Level up your writing and blogging with AI</generator>
    <category>Blog</category>
    <category>Tech</category>
    <pubDate>Sat, 16 May 2026 06:57:34 +0000</pubDate>
    <description/>
    <title>Blog (buffer) - Fred Wu&apos;s Tech</title>
    <atom:link type="application/rss+xml" rel="self" href="http://persumi.com/u/fredwu/tech/e/blog/t/buffer/feed/rss"></atom:link>
    <item>
      <pubDate>Wed, 20 Jun 2012 09:09:00 +0000</pubDate>
      <guid>http://persumi.com/u/fredwu/tech/e/blog/p/rails-tip-render-views-outside-of-controllers-or-views</guid>
      <comments>http://persumi.com/u/fredwu/tech/e/blog/p/rails-tip-render-views-outside-of-controllers-or-views</comments>
      <category>Blog</category>
      <category>Tech</category>
      <author>ifredwu@gmail.com (Fred Wu)</author>
      <description>&lt;![CDATA[&lt;p&gt;
Ever wondered how you could utilise the &lt;code class=&quot;inline&quot;&gt;render&lt;/code&gt; method outside the context of Rails controllers and views? If you wonder why anyone would do that. Well, imagine you are building an awesome form builder, you need to output and/or store rendered partials in the buffer. How do you do that?&lt;/p&gt;
&lt;p&gt;
For example, what if you want to do this in your view?&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;ruby language-ruby&quot;&gt;&lt;%=raw Awesome::FormBuilder.new(some_options).html %&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;
You could do something like this:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;ruby language-ruby&quot;&gt;module Awesome
  class FormBuilder &lt; AbstractController::Base
    include AbstractController::Rendering
    include ActionView::Context
    include ActionView::Helpers::CaptureHelper

    # set the view paths from your engine or from your application root, i.e. Rails.root
    self.view_paths = Awesome::Engine.root.join(&apos;app/views&apos;)

    def initialize(params)
      flush_output_buffer
      @_buffer = &apos;&apos;
      add_to_buffer(params)
    end

    def html
      @_buffer
    end

    private

    def add_to_buffer(params)
      # some logic to add rendered content to @_buffer
    end
  end
end&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;
The idea is to mixin the &lt;code class=&quot;inline&quot;&gt;render&lt;/code&gt; method, but also ensuring the view buffer is correctly reset with &lt;code class=&quot;inline&quot;&gt;flush_output_buffer&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;
Hope that helps. :)&lt;/p&gt;
]]&gt;</description>
      <link>http://persumi.com/u/fredwu/tech/e/blog/p/rails-tip-render-views-outside-of-controllers-or-views</link>
      <title>[Rails Tip] Render views outside of Controllers or Views</title>
    </item>
  </channel>
</rss>