title: Append ruby partial in javascript, and pass a rails variable
body: <p>Creating a chat component with ActionCable in Rails5.  I learned today that render partial, even in .js.erb does supposedly doesn't work. <code>render</code> specifically is the issue.  So now I'm trying to call a partial, and pass a ruby variable to it. </p>
  
  <p>I have tried many things, currently this is how I'm trying to accomplish it:</p>
  
  <pre><code>chatbox.append(&lt;%= j (Erubis::Eruby.new(File.read(File.join(Rails.root, 'app/views/msgs',
          '_msg.html.erb'))).result(msg: @msg)) %&gt;);
  </code></pre>
  
  <p>and the error is </p>
  
  <pre><code> undefined method `self_or_other' for #&lt;Erubis::Eruby:0x007f832bbb8590&gt;
  </code></pre>
  
  <p>So the partial is there, but the variable is not correct.</p>
  
  <hr>
  
  <p>views/msgs/_msg.html.erb</p>
  
  <pre><code>&lt;li class="&lt;%=  self_or_other(msg) %&gt;"&gt;
    &lt;div class="avatar"&gt;
      &lt;%# if msg_interlocutor(msg).avatar.url(:thumb) == "thumb/missing.png" %&gt;
      &lt;%= image_tag(msg_interlocutor(msg).avatar.url(:thumb), class: "convoPic")%&gt;
  &lt;/div&gt;
  &lt;/li&gt;
  </code></pre>
  
  <p>I also tried:</p>
  
  <pre><code>chatbox.append(&lt;%= j (Msg.new(File.read(File.join(Rails.root, 'app/views/msgs',
          '_msg.html.erb'))).result(msg: @msg)) %&gt;);
  </code></pre>
  
  <p>And get this error:
  <code>When assigning attributes, you must pass a hash as an argument.</code></p>
  
  <p>Trying with render:</p>
  
  <pre><code>App.msgs = App.cable.subscriptions.create('MsgsChannel', {  
    received: function(data) {
      var chatbox = "#chatbox_" + data.convo + " .chatboxcontent"
      var id = data.convo;
      var sender_id = data.user.id;
      var reciever_id = data.receiver;
      &lt;%= @msg %&gt; = data.msg
      $(chatbox).append("&lt;%= escape_javascript render(:partial =&gt; 'msgs/msg', :locals =&gt; { :msg =&gt; @msg }) %&gt;");
  
      chatbox.scrollTop(chatbox[0].scrollHeight);
    },
    renderMsg: function(data) {
      console.log(data)
    }
  });
  </code></pre>
  
  <p>And error I receive:</p>
  
  <pre><code>undefined method `render' for #&lt;#&lt;Class:0x007fe976b5c180&gt;:0x007fe9773ed470&gt;
  </code></pre>
  
  <p>How do I properly call in a partial, pass it a ruby variable (with the msg record). Thank you!!</p>