Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

This project is archived and is in readonly mode.

routing and url_for doesn't accept dots in the custom parameters

#5994

hi

In rails routes.rb file I have something like this:

scope '(:locale)', :module => 'website',  :locale => /en|pl/ do
    
    root :to => 'shop#index'
    
    scope 'img' do
      match 's/', :to => 'dynamic_images#index'
      match 's/:system_user_file_id/:size/:dummy/:test', :to => 'dynamic_images#show_system_user_image'
    end
    
end

and when i try to access the image with the url like this :

http://localhost/img/s/21/normal/testjpg/23

or in the console :

reload!;app.url_for({:controller => "website/dynamic_images", :action => "show_system_user_image", :system_user_file_id => "21" , :size => "normal", :dummy => "testjpg", :test => "23"})

the routing works fine, but when i add to any of the parameters a dot "." , for e.g:

http://localhost/img/s/21/normal/test.jpg/23
http://localhost/img/s/21/no.rmal/testjpg/23
http://localhost/img/s/2.1/normal/testjpg/23
http://localhost/img/s/21/normal/testjpg/2.3
reload!;app.url_for({:controller => "website/dynamic_images", :action => "show_system_user_image", :system_user_file_id => "2.1" , :size => "normal", :dummy => "testjpg", :test => "23"})
reload!;app.url_for({:controller => "website/dynamic_images", :action => "show_system_user_image", :system_user_file_id => "21" , :size => "nor.mal", :dummy => "testjpg", :test => "23"})
reload!;app.url_for({:controller => "website/dynamic_images", :action => "show_system_user_image", :system_user_file_id => "21" , :size => "normal", :dummy => "test.jpg", :test => "23"})

I get the errors:
(console errors)

Reloading...
ActionController::RoutingError: No route matches {:controller=>"website/dynamic_images", :action=>"show_system_user_image", :system_user_file_id=>"21", :size=>"normal", :dummy=>"tes.tjpg", :test=>"23"}

from /home/pawel/AptanaStudio3Workspace/ndc_rails3/bundler_files/ruby/1.9.1/gems/actionpack-3.0.3/lib/action_dispatch/routing/route_set.rb:424:in `raise_routing_error'
from /home/pawel/AptanaStudio3Workspace/ndc_rails3/bundler_files/ruby/1.9.1/gems/actionpack-3.0.3/lib/action_dispatch/routing/route_set.rb:406:in `rescue in generate'
from /home/pawel/AptanaStudio3Workspace/ndc_rails3/bundler_files/ruby/1.9.1/gems/actionpack-3.0.3/lib/action_dispatch/routing/route_set.rb:395:in `generate'
from /home/pawel/AptanaStudio3Workspace/ndc_rails3/bundler_files/ruby/1.9.1/gems/actionpack-3.0.3/lib/action_dispatch/routing/route_set.rb:453:in `generate'
from /home/pawel/AptanaStudio3Workspace/ndc_rails3/bundler_files/ruby/1.9.1/gems/actionpack-3.0.3/lib/action_dispatch/routing/route_set.rb:481:in `url_for'
from /home/pawel/AptanaStudio3Workspace/ndc_rails3/bundler_files/ruby/1.9.1/gems/actionpack-3.0.3/lib/action_dispatch/routing/url_for.rb:131:in `url_for'
from (irb):86
from /home/pawel/AptanaStudio3Workspace/ndc_rails3/bundler_files/ruby/1.9.1/gems/railties-3.0.3/lib/rails/commands/console.rb:44:in `start'
from /home/pawel/AptanaStudio3Workspace/ndc_rails3/bundler_files/ruby/1.9.1/gems/railties-3.0.3/lib/rails/commands/console.rb:8:in `start'
from /home/pawel/AptanaStudio3Workspace/ndc_rails3/bundler_files/ruby/1.9.1/gems/railties-3.0.3/lib/rails/commands.rb:23:in `<top (required)>'
from script/rails:6:in `require'
from script/rails:6:in `<main>'



but this route works fine :

http://localhost/img/s/21/normal/testjpg/2.3

and this url_for command doesn't:

reload!;app.url_for({:controller => "website/dynamic_images", :action => "show_system_user_image", :system_user_file_id => "21" , :size => "normal", :dummy => "testjpg", :test => "2.3"})

my stack details are :


Ubuntu 10.10, Rails 3.0.3

ruby 1.9.2p0 (2010-08-18 revision 29036) [i686-linux]
Linux pawel-desktop 2.6.35-23-generic-pae #37-Ubuntu SMP Fri Nov 5 20:57:06 UTC 2010 i686 GNU/Linux

irb -v
irb 0.9.6(09/06/30)

gem -v
1.3.7

Gems included by the bundle:
  * abstract (1.0.0)
  * actionmailer (3.0.3)
  * actionpack (3.0.3)
  * activemerchant (1.9.0)
  * activemodel (3.0.3)
  * activerecord (3.0.3)
  * activeresource (3.0.3)
  * activesupport (3.0.3)
  * arel (2.0.3)
  * braintree (2.6.2)
  * builder (2.1.2)
  * bundler (1.0.3)
  * carrierwave (0.5.0)
  * erubis (2.6.6)
  * hoe (2.7.0)
  * i18n (0.4.2)
  * i18n_routing (0.4.5)
  * json_pure (1.4.6)
  * liquid (2.2.2)
  * mail (2.2.10)
  * mime-types (1.16)
  * mysql (2.8.1)
  * polyglot (0.3.1)
  * rack (1.2.1)
  * rack-mount (0.6.13)
  * rack-test (0.5.6)
  * rails (3.0.3)
  * railties (3.0.3)
  * rake (0.8.7)
  * rake-compiler (0.7.1)
  * rmagick (2.13.1)
  * rubyforge (2.0.4)
  * sqlite3-ruby (1.3.2)
  * thor (0.14.4)
  * treetop (1.4.9)
  * tzinfo (0.3.23)
  * will_paginate (3.0.pre2)

Reported by Pawel Barcik · November 17th, 2010 @ 04:14 PM

State: resolved
Milestone: 3.x
Assigned to: Andrew White Andrew White
Importance: Low

Activity

  1. Andrew White
    Andrew White
    • State changed from new to invalid
    • Importance changed from to Low

    By default all routes have an optional format parameter added to them unless it is already in the route. To allow this to work dynamic segments don't allow periods by default. This can be overridden by using a regexp requirement and turning off format:

      match '/assets/:file', :to => 'assets#show', :file => %r{[^/]+}, :format => false
    

    Adjust the regexp to allow/disallow whatever characters you need. The example allows everything but slash - use /.+/ if you want to match anything.

    BTW, this issue has cropped up multiple times - please use the ticket search to see if your issue has already been reported before creating a new ticket.

    November 17th, 2010 @ 05:36 PM

  2. Pawel Barcik
    Pawel Barcik

    I have checked the other tickets but I was looking for a valid tickets bafore.

    I have found some other "invalid" tickets related to this subject but they werent actually pointing out this issue directly.
    Below I am placing the links to other tickets for other users:

    https://rails.lighthouseapp.com/projects/8994/tickets/882-map-resource-nested-paths-don-t-always-resolve-properly
    
    https://rails.lighthouseapp.com/projects/8994/tickets/75-routing-receptors-with-a-dot-in-the-name
    

    That is all I was able to find, if you have any more examples , please add it in next comments.

    From what I remember there was no direct information about it in the rails guides so maybe it would be worth putting it there
    with big red letters ;)

    November 18th, 2010 @ 09:24 AM

  3. Andrew White
  4. Repository
    Repository
    • State changed from open to resolved

    (from [b4205b40ee893ae35ce468057e9ac62ffaea4ec4]) Add notes on how to override the default :id constraint [#5994 state:resolved] https://github.com/rails/rails/commit/b4205b40ee893ae35ce468057e9ac...

    February 14th, 2011 @ 01:02 AM

  5. Repository