title: Rails routing error: No route matches [DELETE]
body: <p>I'm a ruby on rails noob having some trouble deleting a resource with a <em>form_for</em>. </p>
  
  <p>I'm trying to create a wish-list for products where users can add multiple instances of the same product to their list. Rather than create a unique data-base entry for each product on the list (regardless of whether the same product is already on the list), I've included a counter column, 'row,' which increases as the user adds multiples of the same product to his or her wish list. By the same logic, I want the delete action to first decrease this counter until it reaches 0, and then remove the item from the data-base. </p>
  
  <p>Here's what I've got: </p>
  
  <p>The error message:</p>
  
  <pre><code> No route matches [DELETE] "/wish"
   Routes
  
   Routes match in priority from top to bottom
  
   wishes_path        GET     /wishes(.:format)           wishes#index
                      POST    /wishes(.:format)           wishes#create 
   new_wish_path      GET     /wishes/new(.:format)       wishes#new
   edit_wish_path     GET     /wishes/:id/edit(.:format)  wishes#edit
   wish_path          GET     /wishes/:id(.:format)       wishes#show
                      PATCH   /wishes/:id(.:format)       wishes#update
                      PUT     /wishes/:id(.:format)       wishes#update
                      DELETE  /wishes/:id(.:format)       wishes#destroy
  </code></pre>
  
  <p><em>wishes/index.html.erb</em></p>
  
  <pre><code>&lt;div class="wishes_body"&gt;
    &lt;h2&gt;Your Wish-List&lt;/h2&gt;
  
    &lt;table&gt;
      &lt;thead&gt;
        &lt;tr&gt;
          &lt;th class="field-label col-md-2 active"&gt;
            &lt;label&gt;Name&lt;/label&gt;
          &lt;/th&gt;
          &lt;th class="col-md-3"&gt;Description&lt;/th&gt;
          &lt;th class="col-md-1"&gt;Amount&lt;/th&gt;
          &lt;th class="col-md-1"&gt;Number&lt;/th&gt;
          &lt;th class="col-md-2"&gt;Total&lt;/th&gt;
          &lt;th colspan="3" class="col-md-3"&gt;Remove&lt;/th&gt;
        &lt;/tr&gt;
      &lt;/thead&gt;
  
      &lt;tbody&gt;
          &lt;% @wishes.all.each do |w| %&gt;
              &lt;%= render partial: 'wish', object: w %&gt;
          &lt;% end %&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p><em>_wish.html.erb</em></p>
  
  <pre><code>&lt;tr&gt;
    &lt;td class="field-label col-md-2 active"&gt;
      &lt;label&gt;&lt;%= wish.product.name %&gt;&lt;/label&gt;
    &lt;/td&gt;
    &lt;td class="col-md-3"&gt;&lt;%= wish.product.description %&gt;&lt;/td&gt;
    &lt;td class="col-md-1"&gt;&lt;%= '%.2f' % (wish.product.amount/100.00) %&gt;&lt;/td&gt;
    &lt;td class="col-md-1"&gt;&lt;%= wish.total %&gt;&lt;/td&gt;
    &lt;td class="col-md-2"&gt;&lt;%= '%.2f' % ((wish.product.amount/100.00) * wish.total) %&gt;&lt;/td&gt;
    &lt;%= form for(wish_path(wish), :html =&gt; { method: 'delete' }) do %&gt;
      &lt;td&gt;&lt;%= f.label(:i, "How many:") %&gt;&lt;/td&gt;
      &lt;td&gt;&lt;%= f.number_field(:i) %&gt;&lt;/td&gt;
      &lt;td&gt;&lt;%= f.submit :value =&gt; "Remove" %&gt;&lt;/td&gt;
    &lt;% end %&gt;
  &lt;/tr&gt;
  </code></pre>
  
  <p><em>controllers/wishes.controller.rb</em></p>
  
  <pre><code>class WishesController &lt; ApplicationController
  
      def index
          @wishes = Wish.where("user_id = ?", "#{current_user.id}")
      end
  
      def show
          @user = current_user
          @products = @user.wish_list.products.order("created_at DESC")
      end
  
      def create
          @product = Product.find(params[:product_id])
          if Wish.where(user_id: "#{current_user.id}", product_id: "#{@product.id}").exists?
              @wish = Wish.where(user_id: "#{current_user.id}", product_id: "#{@product.id}").first
              @wish.total += 1
  
          else
              @wish = @product.wishes.new
              @wish.user = current_user
              @wish.total = 1
          end
          respond_to do |format|
              if @wish.save
                  format.html { redirect_to action: "index", notice: 'You have added &lt;%= @wish.product %&gt; to your wish list.' }
                  format.json { render :index, status: :created }
              else
                  format.html { redirect_to @product, alert: 'Wish was not created succesfully.' }
                  format.json { render json: @wish.errors, status: :unprocessable_entity }
              end
          end
      end
  
      def destroy
          case i = params[:i]
          when @wish.total &gt; i
              @wish.total -= i
              respond_to do |format|
                  format.html { redirect_to action: 'index', notice: 'You removed the item from your wish-list.' }
                  format.json { head :no_content }
              end
          when @wish.total == i
              @wish.destroy
              respond_to do |format|
                  format.html { redirect_to action: 'index', notice: 'You removed the item from your wish-list.' }
                  format.json { head :no_content }
              end
          else
              format.html { redirect_to action: 'index', alert: 'You cannot remove more items than you have on your list.' }
              format.json { head :no_content }
          end
  
      end
  end
  </code></pre>
  
  <p><em>config.routes.rb</em></p>
  
  <pre><code>Rails.application.routes.draw do
  
    root 'static_pages#index'
  
    get 'static_pages/about'
  
    get 'static_pages/contact'
  
    get 'static_pages/landing_page'
  
    post 'static_pages/thank_you'
  
    resources :orders, only: [:index, :show, :new, :create]
  
    resources :users
  
    devise_for :users, :controllers =&gt; { :registrations =&gt; "my_devise/registrations" }, 
                       :path =&gt; '', :path_names =&gt; {:sign_in =&gt; 'login', :sign_out =&gt; 'logout', :sign_up =&gt; 'register'}
  
    resources :wishes
  
    resources :products do
      resources :comments
    end
  
    resources :payments
  end
  </code></pre>