title: adding a method to non-restful routes in rails 4
body: <p>i would like to perform an action on some of my routes, the problem is they are not in a 'resources' block because I need named methods for each. I want to be able to toggle the state of each an attribute in each item in an index type view. I wwas attempting to incorporate <a href="http://buckybits.blogspot.co.uk/2011/09/simple-ajax-property-toggle-in-rails-30.html" rel="nofollow">this</a> tutorial.</p>
  
  <pre><code>  devise_for :admins  # The priority is based upon order of creation: first created -&gt; highest priority.
    root 'home#index'
    resources :entries, :only =&gt; [:index, :new, :create] 
    namespace :admin do 
      namespace :entries do
        match :pending, :via =&gt; [:get, :post], :collection =&gt; { :toggle_approve =&gt; :put}
        match :rejected, :via =&gt; [:get, :post], :collection =&gt; { :toggle_approve =&gt; :put}
        match :approved, :via =&gt; [:get, :post], :collection =&gt; { :toggle_approve =&gt; :put}
      end
    end
  </code></pre>
  
  <p>entries controller </p>
  
  <pre><code>class Admin::EntriesController &lt; ApplicationController
  
    expose(:entries){@entries}
  
  
    def index
    end
  
    def show
    end
  
    def approved 
      @entries = Photo.with_approved_state
    end
  
    def pending
      @entries = Photo.with_pending_state 
    end
  
    def rejected
      @entries = Photo.with_rejected_state
    end
  
    def toggle_approve  
      @a = Photo.find(params[:id])  
      @a.toggle!(:workflow_state)  
      render :nothing =&gt; true  
    end
  </code></pre>
  
  <p>rake routes</p>
  
  <pre><code>                   Prefix Verb     URI Pattern                       Controller#Action
          new_admin_session GET      /admins/sign_in(.:format)         devise/sessions#new
              admin_session POST     /admins/sign_in(.:format)         devise/sessions#create
      destroy_admin_session DELETE   /admins/sign_out(.:format)        devise/sessions#destroy
             admin_password POST     /admins/password(.:format)        devise/passwords#create
         new_admin_password GET      /admins/password/new(.:format)    devise/passwords#new
        edit_admin_password GET      /admins/password/edit(.:format)   devise/passwords#edit
                            PATCH    /admins/password(.:format)        devise/passwords#update
                            PUT      /admins/password(.:format)        devise/passwords#update
  cancel_admin_registration GET      /admins/cancel(.:format)          devise/registrations#cancel
         admin_registration POST     /admins(.:format)                 devise/registrations#create
     new_admin_registration GET      /admins/sign_up(.:format)         devise/registrations#new
    edit_admin_registration GET      /admins/edit(.:format)            devise/registrations#edit
                            PATCH    /admins(.:format)                 devise/registrations#update
                            PUT      /admins(.:format)                 devise/registrations#update
                            DELETE   /admins(.:format)                 devise/registrations#destroy
                       root GET      /                                 home#index
                    entries GET      /entries(.:format)                entries#index
                            POST     /entries(.:format)                entries#create
                  new_entry GET      /entries/new(.:format)            entries#new
      admin_entries_pending GET|POST /admin/entries/pending(.:format)  admin/entries#pending {:collection=&gt;{:toggle_approve_article=&gt;:put}}
     admin_entries_rejected GET|POST /admin/entries/rejected(.:format) admin/entries#rejected {:collection=&gt;{:toggle_approve_article=&gt;:put}}
     admin_entries_approved GET|POST /admin/entries/approved(.:format) admin/entries#approved {:collection=&gt;{:toggle_approve_article=&gt;:put}}
  </code></pre>