title: With Active Model Serializers, how do you render a partial?
body: <p>I'm creating a newsfeed and have a JSON response set up with Active Model Serializers gem.  I'd like to render a regular ERB partial and have it as one of the attributes in the JSON.</p>
  
  <p>controllers/posts_controller.rb:</p>
  
  <pre><code>def index
    @posts = Post.all
    respond_to do |format|
      format.json { render json: @posts.to_a, each_serializer: PostSerializer }
    end
  end
  </code></pre>
  
  <p>serializers/post_serializer.rb:</p>
  
  <pre><code>def event_html
    ApplicationController.new.render_to_string(:partial =&gt; 'events/event', :locals =&gt; { :event =&gt; object.event }) if object.event
  end
  </code></pre>
  
  <p>Unfortunately, my view has some code that uses helpers and the request object (urls), and I'm getting errors when I try to do this.  </p>
  
  <p>events/_event.html.erb:</p>
  
  <pre><code>&lt;div class="event"&gt;
    &lt;h4 class="title"&gt;&lt;%= link_to event.name, event %&gt;&lt;/h4&gt;
    &lt;div class="date"&gt;&lt;%= date_range event.start_at, event.end_at %&gt;&lt;/div&gt;
    &lt;div class="description"&gt;&lt;%= event.description.html_safe %&gt;&lt;/div&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p><code>undefined method `host' for nil:NilClass</code></p>
  
  <p>Any ideas of a good way to solve this problem?  </p>