title: rails3: How to render json data to a .js view?
body: <p>I tried following the instructions in this <a href="https://stackoverflow.com/questions/2566759/how-can-i-generate-json-from-respond-to-method-in-rails">answer</a> for rendering json data in a .js.erb file. But I get this error: </p>
  
  <pre><code>ActionView::MissingTemplate (Missing template activities/json, application/json with {:handlers=&gt;[:erb, :builder], :formats=&gt;[:js, :html], :locale=&gt;[:en, :en]}.
  </code></pre>
  
  <p>I have a good amount of data to send to the user hence I wanted to send as json than text/html.</p>
  
  <p>Here is my controller 'some_controller.rb':</p>
  
  <pre><code>def some_action
      @hash = ...
      @var = ...
      .
      .
  
      respond_to do |format|
          format.js { render :json }
      end
  end
  </code></pre>
  
  <p>Here is my view in views/some_controller/some_action.js.erb:</p>
  
  <pre><code>$("#some_div").html("&lt;%=j render :partial =&gt; 'some_controller/another_action' %&gt;");
  </code></pre>
  
  <p>Here is my another_action.html.erb:</p>
  
  <pre><code>&lt;%= self.formats = ["html"] %&gt;
  Var1 = &lt;%= @var1 %&gt;
  Hash1 = &lt;%= @hash1.inspect %&gt;
  </code></pre>
  
  <p>Is the answer in the link above wrong? Can't we send json data to a js.erb file? I tried to convert the vars and hashes using .to_json. For example:</p>
  
  <pre><code>@hash1 = someMethod(someParams).to_json
  </code></pre>
  
  <p>But @hash1 was rendered as a string in my final html.erb which cannot be parsed, of course! Is there something I did wrong or missed?</p>
  
  <p>Also there are no tutorials available online for json rendering in rails, can somebody please provide some nice links to learn and json and rails? Help is greatly appreciated. Thanks in advance.</p>
  
  <p>Thank you,
  pR</p>