title: Proper route to get controller action to work properly with passed argument - Rails
body: <pre><code>Rails 4.2.1
  Ruby 2.1.5
  </code></pre>
  
  <p>In my routes.rb, I have:</p>
  
  <pre><code>get '/activate_test_set' =&gt;  'test_sets#activate_test_set'
  </code></pre>
  
  <p>In test_sets_controller.rb, I have:</p>
  
  <pre><code>def activate_test_set test_set
    test_set.update_attribute(status: 'active')
    render test_sets_url
  end
  </code></pre>
  
  <p>In my views/test_sets/index.html, I have:</p>
  
  <pre><code>&lt;%= link_to "#{t('activate')}", activate_test_set_path(test_set) %&gt;
  </code></pre>
  
  <p>When I'm in the view, if I click on the link, I get the following in the development error log:</p>
  
  <pre><code>Started GET "/activate_test_set.1" for ::1 at 2016-01-01 13:23:55 -0800
  Processing by TestSetsController#activate_test_set as 
  Completed 500 Internal Server Error in 5ms (ActiveRecord: 0.0ms)
  
  ArgumentError (wrong number of arguments (0 for 1)):
   app/controllers/test_sets_controller.rb:69:in `activate_test_set'
  </code></pre>
  
  <p>Whats' the proper routes.rb declaration to make this work correctly?</p>
  
  <p>I also tried this in routes.rb:</p>
  
  <pre><code>get '/activate_test_set/:id' =&gt;  'test_sets#activate_test_set'
  </code></pre>
  
  <p>and this is what I get:</p>
  
  <pre><code>Started GET "/activate_test_set.1" for ::1 at 2016-01-01 15:14:57 -0800
      SELECT `schema_migrations`.* FROM `schema_migrations`
  ActionController::RoutingError (No route matches [GET] "/activate_test_set.1"): 
  </code></pre>
  
  <h1>Solution:</h1>
  
  <p>Following some additional experimentation, here's how I solved this problem. Being a newbie, I am not sure this is the best solution, but here it goes:</p>
  
  <pre><code>match "activate_test_set/:id", :to =&gt; "test_sets#activate_test_set", :as =&gt; :activate_test_set, via: [:get]
  </code></pre>