Weston Ganger
Weston Ganger

Reputation: 6712

Ruby runs on page load in Javascript in slim file

Basically I want to render this partial and build an object when someone clicks the button.

The problem I am having is that on page load the '@node.logical_ports.new' portion is actually being run, I don't want it to run until event has been triggered.

javascript:
  $(function(){
    $('body').on('click', '.add', function(){
      $(this).html("#{escape_javascript(render 'logical_port_form', logical_port: @node.logical_ports.new)}");
    });
  });

Upvotes: 0

Views: 551

Answers (1)

user229044
user229044

Reputation: 239382

That's impossible, you cannot send Ruby down the wire to the client to be run at a later date. Ruby executes server-side, before the client has received anything. You need to rethink the way your code is architected.

Upvotes: 2

Related Questions