title: Rails - json.erb template
body: <p>I have been trying to figure out a way to customize JSON with special fields, custom formats, etc etc.  I have created an as_json and to_xml method in my model to formulate the object how I need.  This works well but it is sloppy because some of my helper methods had to move into the model, because I need the formats in the helpers and model.  I also think it is sloppy code and makes the model out of control.</p>
  
  <p>I have been able to get a format with json.erb working but don't think it is working 100% correct either and the callback doesn't append either.  Anyone get this working</p>
  
  <p>Here is what I got so far.</p>
  
  <p>api calls format.json </p>
  
  <p>template called is items.json.erb</p>
  
  <pre><code>&lt;% @items.each do |item| %&gt;
  &lt;%= { :item =&gt; { :id =&gt; item.id, :name =&gt; item.name }.to_json.html_safe  %&gt;
  &lt;% end %&gt;
  </code></pre>
  
  <p>This works but seems odd.  Anyone have suggestions or have a way to do this?</p>
  
  <p>btw  did this for the callback to work</p>
  
  <pre><code>&lt;%= params[:callback]+"(" if params[:callback]  %&gt;
  &lt;% @items.each do |item| %&gt;
      &lt;%= { :item =&gt; { :id =&gt; item.id, :name =&gt; item.name }.to_json.html_safe  %&gt;
  &lt;% end %&gt;
  &lt;%= ")" if params[:callback]  %&gt;
  </code></pre>