title: Call a controller method via button in Rails
body: <p>I want to create a button in views/companies/edit.html.haml for <code>destroy_referrals</code> method, but I can't get the button to work. To call the action on a button I tried to create a new route, but I am still receiving the error <em>The action 'destroy_referrals' could not be found for CompaniesController</em></p>
  
  <p>I created a <code>destroy_referrals</code> method in <code>Admin::CompaniesController</code>,</p>
  
  <pre><code>def destroy_referrals
      load_company
      @company.destroy_referrals
      flash[:notice] = 'Referrals deleted'
      redirect_to :action =&gt; :index
  end 
  </code></pre>
  
  <p>it manipulates the <code>company.rb</code> model to find the referrals from users with the same company_id and destroys them,</p>
  
  <pre><code>def destroy_referrals
      Referral.joins(:user).where("users.company_id = ?", self.id).destroy_all
  end
  </code></pre>
  
  <p>Some things I've tried below...</p>
  
  <p>routes.rb</p>
  
  <pre><code>post '/destroy_referrals' =&gt; 'admin/companies#destroy_referrals', :as =&gt; 'destroy_referrals'
  </code></pre>
  
  <p>views/companies/edit.html.haml</p>
  
  <pre><code>= button_to 'Destroy Referrals', destroy_referral_path
  
  = button_to 'Destroy Referrals', admin_company_destroy_referral_path(@company)
  </code></pre>