Why is period (.) one of the separators? As it stands, the new routing
code doesn’t recognize ‘file.ext’ as the last component of a URL, which
is sometimes defaulted to nil. See the generated code below.
I don’t know everything about URL encoding, but it seems that period
isn’t one of should-be-escaped characters in a URL.
Thanks in advance!
Doug.
–Generated code–
if (match =
/\A/(user)/(login|logout|show|list)(?:/?\Z|/([^/;.,?]+)/?)\Z/.match(path))
Why is period (.) one of the separators? As it stands, the new routing
code doesn’t recognize ‘file.ext’ as the last component of a URL,
which
is sometimes defaulted to nil. See the generated code below.
An extension is the natural way to specify a resource’s mime type:
/people/1.xml
So it’s now parameterizable:
map.connect ‘/:controller/:id.:format’, :action =>
‘show’, :require => { :method => :get }
class PeopleController …
def show
# The :format param informs respond_to.
respond_to do |wants|
wants.html # renders the rhtml
wants.xml { render :xml => @person.to_xml }
end
end
GET /people/1
GET /people/1.html
GET /people/1.xml
Thank you, Jeremy, for the clear explanation! Indeed, it’s quite a
useful feature.
However, the implementation of it has introduced a problem: a URL that’s
generated by the following route cannot be recognized by the same route.
map.connect ‘/:controller/:action/:file’, :defaults => (:file => nil}
Note that .:format isn’t specified, and then the file segment contains a
dot, but url_for doesn’t escape the dot.
A bug?
Doug.
Jeremy K. wrote:
An extension is the natural way to specify a resource’s mime type:
/people/1.xml
So it’s now parameterizable:
map.connect ‘/:controller/:id.:format’, :action =>
‘show’, :require => { :method => :get }
class PeopleController …
def show
# The :format param informs respond_to.
respond_to do |wants|
wants.html # renders the rhtml
wants.xml { render :xml => @person.to_xml }
end
end
GET /people/1
GET /people/1.html
GET /people/1.xml
jeremy
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.