title: How to invoke a js from link_to in Ruby on Rails?
body: <p>I would like to invoke a js.erb from my <code>link_to</code></p>
  
  <p>I tried this:</p>
  
  <pre><code>&lt;% @categories.each do |category| %&gt;
    &lt;tr&gt;&lt;td&gt;
      &lt;%= link_to category, :controller =&gt; "movies", :action =&gt; "show_category", :category =&gt; category, :method =&gt; :post, :remote =&gt; true%&gt;    
    &lt;/td&gt;&lt;/tr&gt;
  &lt;% end %&gt;
  </code></pre>
  
  <p>This is my complete <code>routes.rb</code> file:</p>
  
  <pre><code>Rails.application.routes.draw do
    resources :movies
    devise_for :users
    # For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html
    root to: "movies#index"
  
    post '/movies/show_category', to: 'movies#show_category', as: 'show_movies_by_category'
  end
  </code></pre>
  
  <p>This is my target function in <code>movies_controller</code> I would like to be called when the <code>link_to</code> is clicked (my understanding is from this function, I could invoke <code>show_category.js.erb</code> Javascript file):</p>
  
  <pre><code>def show_category
    respond_to do |format|
      format.js {render layout: false}
    end
  end
  </code></pre>
  
  <p>But instead of calling <code>movies_controller#show_category</code>, <code>movies_controller#show</code> seems to be invoked. This is what I see in my Rails console:</p>
  
  <pre><code>Started GET "/movies/show_category?category=Romance&amp;method=post" for 127.0.0.1 at 2019-01-06 13:41:47 +0530
  Processing by MoviesController#show as JS
    Parameters: {"category"=&gt;"Romance", "method"=&gt;"post", "id"=&gt;"show_category"}
    Movie Load (0.4ms)  SELECT  "movies".* FROM "movies" WHERE "movies"."id" = ? LIMIT ?  [["id", 0], ["LIMIT", 1]]
    ↳ app/controllers/movies_controller.rb:87
  Completed 404 Not Found in 6ms (ActiveRecord: 0.4ms)
  
  
  
  ActiveRecord::RecordNotFound (Couldn't find Movie with 'id'=show_category):
  
  app/controllers/movies_controller.rb:87:in `set_movie'
  </code></pre>
  
  <p>What am I doing wrong here?</p>