This project is archived and is in readonly mode.
routing and url_for doesn't accept dots in the custom parameters
Reported by Pawel Barcik | November 17th, 2010 @ 04:14 PM | in 3.x
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)
Comments and changes to this ticket
-
Andrew White November 17th, 2010 @ 05:36 PM
- 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.
-
Pawel Barcik November 18th, 2010 @ 09:24 AM
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 ;) -
Andrew White November 18th, 2010 @ 10:20 AM
- State changed from invalid to open
- Milestone set to 3.x
- Assigned user set to Andrew White
Here's a few more that mention urls with periods in them:
https://rails.lighthouseapp.com/projects/8994/tickets/5399-routing-...
https://rails.lighthouseapp.com/projects/8994/tickets/2694-nested-r...
https://rails.lighthouseapp.com/projects/8994/tickets/2536-format-f...
https://rails.lighthouseapp.com/projects/8994/tickets/1064-named-ro...
https://rails.lighthouseapp.com/projects/8994/tickets/4443-url_for-...
https://rails.lighthouseapp.com/projects/8994/tickets/5208-new-rout...You're right though, it should be mentioned in the docs.
-
Repository February 14th, 2011 @ 01:02 AM
- 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...
-
Repository February 14th, 2011 @ 01:02 AM
(from [fd7605826a6e4f7590e4abf42c6c9d0923afc4ef]) Add notes on how to override the default :id constraint [#5994 state:resolved] https://github.com/rails/rails/commit/fd7605826a6e4f7590e4abf42c6c9...
Create your profile
Help contribute to this project by taking a few moments to create your personal profile. Create your profile »
<h2 style="font-size: 14px">Tickets have moved to Github</h2>
The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>
People watching this ticket
Referenced by
- 6134 router.rb match and :format problem This crops up frequently - see my response to #5994. I re...
- 6126 path helper problem And #5994 where I've listed some more tickets that have r...
- 5994 routing and url_for doesn't accept dots in the custom parameters (from [b4205b40ee893ae35ce468057e9ac62ffaea4ec4]) Add not...
- 5994 routing and url_for doesn't accept dots in the custom parameters (from [fd7605826a6e4f7590e4abf42c6c9d0923afc4ef]) Add not...