Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9243235
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T08:45:56+00:00 2026-06-18T08:45:56+00:00

Given the code (in routes.rb): resources :products do member do get :delete #this works

  • 0

Given the code (in routes.rb):

  resources :products do
    member do
      get :delete #this works
      delete delete: "products#destroy" #this doesn't work
      delete "delete" => "products#destroy" #but this works
    end
  end

Why the line delete delete: "products#destroy" doesn’t work and the line delete "delete" => "products#destroy" works?

Rails version 3.2.11

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T08:45:57+00:00Added an answer on June 18, 2026 at 8:45 am

    The reason why this doesn’t work and if you follow the error backtrace is because of the following line in the mapper.rb in Rails.

    def match(path, *rest)
      if rest.empty? && Hash === path
        options  = path
        path, to = options.find { |name, value| name.is_a?(String) }
        options[:to] = to
        options.delete(path)
        paths = [path]
      else
        options = rest.pop || {}
         paths = [path] + rest
      end
    
      options[:anchor] = true unless options.key?(:anchor)
    
      if options[:on] && !VALID_ON_OPTIONS.include?(options[:on])
        raise ArgumentError, "Unknown scope #{on.inspect} given to :on"
      end
      paths.each { |_path| decomposed_match(_path, options.dup) }
      self
    end
    

    This is called by all the methods behind the scenes (e.g delete, post, get, put). The line that we are specifically looking for is the one that goes like this:

    path, to = options.find { |name, value| name.is_a?(String) }
    

    Not sure why they are checking against a String but since the name is a symbol and not a String but a Symbol. That pretty much sends that path as a nil value into decomposed_match causing somewhere down the line the reason why you cannot use a symbol in the routes.

    NOTE

    resources :products do
      member do
        get :delete #this works
        delete delete: "products#destroy" #this doesn't work
        delete "delete" => "products#destroy" #but this works
      end
    end
    

    The reason why get :delete works is because of the line before the match method is called.

    Specifically under this method

    def map_method(method, *args, &block)
      options = args.extract_options!
      options[:via] = method
      args.push(options)
      match(*args, &block)
      self
    end
    

    the line args.extract_options! removes a hash out of the array. You can find this under the file extract_options.rb which is an added method to the class Array.

    Anyhow, since get :delete is not a hash but a single parameter it gets mapped to something like this

    Path: [delete]
    Options [{via: "get"}]
    

    Now, the other ones get mapped like this take for example delete delete: "product#destroy"

    Path {:delete=>"collaborators#destroy", via: "delete"}
    Options []
    

    Then it goes back to my original statement as to why Symbols don’t work in the routes.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Can anyone explain why this code with the given routes returns the first route?
Given this code, tableButton = new JButton(new ImageIcon(80F_FG2015.GIF)); how would I get that String
Given the following code: resources :subjects do resources :partipicants end I want to route
i know the basics of recursion but in the given code i m facing
Given this code: List<Integer> ints = new ArrayList<Integer>(); // Type mismatch: // cannot convert
Given this code: var arrayStrings = new string[1000]; Parallel.ForEach<string>(arrayStrings, someString => { DoSomething(someString); });
I've seen this code a ton on this site, but I can't seem to
Given the following code, in my ASP.NET webform app; void foo(RouteCollection routes){ routes.MapPageRoute(string.Empty, testroute,
I have the following code: $r->find('user')->via('post')->over(authenticated => 1); Given that route I can get
I have the following code in my routes.rb file: resources :wbs_nos, except: [:new, :create]

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.