title: execute erb function only on onclick event
body: <p>I am trying to build a ruby on rails app where a button click would call a specific function. i put the function in a helper module and I am calling the function with the onclick event. my issue is that it seems like teh ERB code is run anyway, even when I do not click the button. I tested the button by replacing the call to the function by an alert which works properly, only popping up when I click the button, but it seems like that mixing erb inside html makes it run automatically. I also tried to pass through an intermediary step by adding a javascript function called by the onclick event, but it does not solve my issue as the code is run anyway.</p>
  
  <p><strong>index.html.erb</strong></p>
  
  <pre><code>&lt;input type="button" name="test" value="Charger en masse" onclick="&lt;%charger_photos%&gt;"&gt;
  
  module CartephotosHelper
    def charger_photos
      @test=Array.new
      Dir['./public/images/*'].each do |file_name|
        @test.push(file_name)
        next if File.directory? file_name 
      end
    end
  end
  </code></pre>
  
  <p>test by using javascript to call the fucntion outside of the onclick event</p>
  
  <p><strong>index.html.erb</strong></p>
  
  <pre><code>&lt;script type="text/javascript"&gt;
    function chargermasse(){ 
      &lt;%charger_photos%&gt;
    }
  &lt;/script&gt;
  &lt;input type="button" name="test" value="Charger en masse" onclick="chargermasse()"&gt;
  </code></pre>