title: Call a controller method in a view using onclick option
body: <p>Hi I have the following problem. I would like to call a controller method which executes some sql statements by onklick option of a button or a link. </p>
  
  <p>So I got a method "publish" in my controller. It looks sth like this:</p>
  
  <pre><code>def publish
    do execute sql statements
    flash[:notice] = 'sql statements executed.'
  end
  </code></pre>
  
  <p>And in my view I would like to have a button or a link to call this method like this:</p>
  
  <pre><code>&lt;input type="button" onclick="&lt;% controller.publish %&gt;"&gt;
  </code></pre>
  
  <p>But I get the error: </p>
  
  <blockquote>
    <p>undefined local variable or method</p>
  </blockquote>
  
  <p>I also tried to route it to use this method as :action. That did not work as well. I searched now for a while and found some solutions by making this method a helper_method, though I get the same error again.
  I'm pretty new to Ruby and Rails so I hope you can help me. </p>