#13 √ invalid
Doug Ramsay

Allow SEO friendly resources (ex. /my-resources)

Reported by Doug Ramsay | April 16th, 2008 @ 09:29 PM

Updated actionpack/lib/action_controller/resources.rb to generate

standard controller name from resource containing hyphen

(ex. :'my-resources').

Updated actionpack/lib/action_controller/routing/route_set.rb to

translate hyphens to underscores in resource names.

Comments and changes to this ticket

  • jack dempsey (jackdempsey)
  • Sam Granieri

    Sam Granieri April 16th, 2008 @ 11:35 PM

    As soon as the patch is modified with tests that verify that it works and it doesnt break anything else i'll give it a +1

  • Joshua Peek

    Joshua Peek April 17th, 2008 @ 01:09 AM

    • → Assigned user changed from “” to “Joshua Peek”
    • → State changed from “new” to “open”

    So this will change any resource with an _ to a -? Example, /open_tickets becomes /open-tickets. If so this is going break everyones urls.

  • Joshua Peek

    Joshua Peek April 17th, 2008 @ 01:12 AM

    • → Title changed from “[PATCH] Allow SEO friendly resources (ex. /my-resources)” to “Allow SEO friendly resources (ex. /my-resources)”
  • Doug Ramsay

    Doug Ramsay April 17th, 2008 @ 01:36 AM

    Joshua

    I think you're reading the patch wrong. If somebody puts in a resource such as:

    :my_resources

    the resource will be unaffected. The change will only affect resources that have a dash, such as :'my-resources'.

    Granted, to Sam's point, I need to add tests for this. The problem I'm having is that the tests and custom assertions in actionpack/test/controller/resources_test.rb make a lot of assumptions about how resources will be passed in. Also, none of the existing tests are run with a resource containing an underscore, such as :my_resources with a controller MyResourcesController (file: my_resources_controller.rb).

  • Joshua Peek

    Joshua Peek April 19th, 2008 @ 10:37 PM

    • → State changed from “open” to “invalid”

    I'm really opposed to these kinds of changes. However, there should be a workaround if you really need to do it.

    map.resources :valid_orders, :as => 'valid-orders'
    

    Let me know if that doesn't work for you.

  • jack dempsey (jackdempsey)

    jack dempsey (jackdempsey) April 19th, 2008 @ 10:55 PM

    Joshua,

    What exactly does "these kinds of changes" mean? If you have a resource named "foo-bar" wouldn't you expect the end result url to have a dash and not an underscore?

    I think :as => 'foo-bar' would work as well, just don't see why...can you think of a situation where the programmer would want :'foo-bar' to be 'foo_bar' in the url? (if they did they'd just use :foo_bar right?)

    So, just curious.

  • Doug Ramsay

    Doug Ramsay April 19th, 2008 @ 11:29 PM

    Joshua,

    I see what you're saying, and your solution does work. My thought was that this would offer a good alternative.

    For now, I plan to submit another patch for resources_test.rb which includes tests for multi-word resources, and for the :as option with multi-word resources (neither of which are currently covered).

  • blj

Please Login or create a free account to add a new comment.

You can update this ticket by sending an email to from your email client. (help)

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

Source available from github

The Git repository resides at http://github.com/rails

Check out the current development trunk (Edge Rails) with:

git clone git://github.com/rails/rails.git

Creating or reviewing a patch

See the contributor guide.

Creating a feature request

Please don't. If you want a new feature in Rails, you'll have to pull up your sleeves and get busy yourself. Or convince someone else to do it. See the contributor guide on how to get going. But posting them here is just going to lead to ticket root.

Creating a bug report

When creating a bug report, be sure to include as much relevant information as possible. Post the code sample that causes the problem. Preferably, alter the unit tests and show through either changed or added tests how the expected behavior is not occuring.

Security vulnerabilities should be reported via an email to security@rubyonrails.org, do not use trac for reporting security vulnerabilities. All content in trac is publicly available as soon as it is posted.

Then don't get your hopes up. Unless you have a "Code Red, Mission Critical, The World is Coming to an End" kinda bug, you're creating this ticket in the hope that others with the same problem will be able to collaborate with you on solving it. Do not expect that the ticket automatically will see any activity or that others will jump to fix it. Creating a ticket like this is mostly to help yourself start on the path of fixing the problem and for others to sign on to with a "I'm having this problem too".

Shared Ticket Bins