title: Using link_to to only call a function in rails when the link is clicked
body: <p>I'm very new to rails.  I'm trying to call a function check() only when a link is clicked, but the controller will also call the function every time the view loads.</p>
  
  <p><strong>Routes:</strong>
  routes.rb</p>
  
  <pre><code>Rails.application.routes.draw do
    get 'welcome/index'
  
    resources :articles
  </code></pre>
  
  <p><strong>Controller:</strong>
  articles_controller.rb</p>
  
  <pre><code>class ArticlesController &lt; ApplicationController
      helper_method :check
      def new
      end
  
      def create
          @article = Article.new(article_params)
  
          @article.save
          redirect_to @article
      end
  
      def check
          puts "check"
      end
  
      def show
          @article = Article.find(params[:id])
      end
  
      def index
          @articles = Article.all
      end
  
      private
          def article_params
              params.require(:article).permit(:title, :text)
          end
  </code></pre>
  
  <p><strong>Model:</strong> article.rb</p>
  
  <pre><code>class Article &lt; ActiveRecord::Base
  
  end
  </code></pre>
  
  <p><strong>View:</strong> index.html.erb</p>
  
  <pre><code>&lt;h1&gt;
    &lt;%= link_to 'Call on click', :onclick =&gt; check() %&gt; 
  &lt;/h1&gt;
  </code></pre>