Reputation: 4072
In older versions of Rails, you could have a parameter that includes a period (something typically reserved to separate it from the format) like this:
map.connect 'c/:domain.:format', :controller=>'home', :action=>'click_credit', :requirements => { :domain => %r([^/;,?]+) }
(nice tutorial here)
However, in more modern versions of Rails (2.3.x) I'm seeing this fails - :domain is catching everything, and :format is blank when the request comes in for /c/amazon.com.html
Any ideas on how to modify it?
Thanks, Tom
Upvotes: 4
Views: 1226
Reputation: 12574
Upgrading to rails 3 should solve your problem. I tried your route in rails 3 and it worked fine (with a minor change to use the new routing syntax):
match 'c/:domain.:format',
:controller=>'home',
:action=>'click_credit',
:domain => %r([^/;,?]+)
# 'c/amazon.com.html' => domain: amazon.com , format: html
If upgrading to rails 3 is not an option, then this might help. Per this answer, I think the :requirements
hash may be the culprit. Try this route and see if it works:
map.connect 'c/:domain.:format',
:controller=>'home',
:action=>'click_credit',
:domain => %r([^/;,?]+)
Upvotes: 3
Reputation: 1257
You need to change the domain into a slug and replace any [period] with a [slash].
The reason is because browsers expect . to define file type and you can not work around this.
Use this gem to make it easy for you.
Upvotes: -1