#url should be renamed to #path... hear me out!
Reported by Carl Lerche | July 11th, 2008 @ 09:36 PM | in 0.9.9
I am hereby placing a formal request that #url be renamed to #path and that a new #url method is created that actually returns #urls. Yes, I realize that there is #relative_url and #absolute_url and yes, I realize that this will affect code using Merb to varying degrees, but I think that it is important that we deal with this sooner than later. Hear me out.
First of all, I believe that every method should try to return what one would expect it to return. I don't think there should be any surprises. When I call a method named url, I would expect it to return a URL and not a path. I strongly believe that a method named URL should return a valid URL as per the RFC (http://www.faqs.org/rfcs/rfc1738.... Methods that return paths should be named path. I think that adding relative_url and absolute_url makes things even more confusing because, what is a relative_url? The URL is relative to what? What is an absolute_url? Is it a normalized URL? No, let's try to keep the Merb API as clear as possible.
Second, Merb is supposed to try to make as little assumptions as to how I want to use it. Naming a method that returns paths #url makes a pretty large assumption: I don't want to build web apps that are spread across multiple domains. Now, check out this sweet little router sample:
r.domain(:administration, "admin.awesome.com") do |admin|
admin.resources :users do |u|
u.resources :comments
u.resources :articles
end
end
r.domain(:awesome, "awesome.com") do |awesome|
awesome.resources :articles
end
r.domain(:great, "great.com") do |great|
great.resources :teams
great.resources :games
end
r.domain(:shared, "some-middle-domain.com") do |shared|
shared.match('/login').to(:controller => "sessions", :action => "new").name(:shared_login)
shared.resources :users
end
path(:administration_users) # => /users
url(:administration_users) # => http://admin.awesome.com/users
path(:shared_login) # => /login
url(:shared_login) # => http://some-middle-domain.com/login
url(:great_teams, :domain => 'admin.awesome.com') # => http://admin.awesome.com/teams
That could be quite awesome... if only #url didn't return paths :D
So, since a change like this would probably break existing code, I start warning people of the change NOW and slate it for a 1.0 release. Merb still isn't at a 1.0 stage, so I say we take advantage of it to fix things like this.
I would be willing to go through the code and make the changes should something like this be approved. Thoughts? Comments?
Comments and changes to this ticket
-

-
Michael D. Ivey (ivey) July 11th, 2008 @ 09:51 PM
url() returns URLs. It returns relative URLs by default. I would not be opposed to a config setting to make url() act like absolute_url by default, but I do not think we should rename it.
Relative URLs like "/foo" and "../../bar" are still URLs, as defined (vaguely) in RFC 1738.
-

David Lee July 17th, 2008 @ 02:29 PM
+1 vote for aliasing absolute_url to url and relative_url to path.
-
Michael Klishin (antares) July 17th, 2008 @ 06:31 PM
- → Assigned user changed from to Michael Klishin (antares)
- → State changed from new to open
- → Milestone changed from to 0.9.4
Talking with Ezra on IRC yesterday we decided that we should not use url method internally so people can override it. I will take on it this weekend.
-
Carl Lerche July 17th, 2008 @ 08:50 PM
I think that, in the end, this is the best solution. Let the hacker decide what (s)he wants to do.
-
Michael Klishin (antares) August 2nd, 2008 @ 11:42 AM
- → Milestone changed from 0.9.4 to 0.9.5
-
Michael Klishin (antares) August 23rd, 2008 @ 03:57 PM
- → Milestone changed from 0.9.5 to 0.9.6
-
Michael Klishin (antares) September 4th, 2008 @ 04:50 AM
- → Milestone changed from 0.9.6 to 0.9.7
-
Michael Klishin (antares) September 4th, 2008 @ 09:43 AM
- → Assigned user changed from Michael Klishin (antares) to Carl Lerche
-
Michael Klishin (antares) September 13th, 2008 @ 06:59 PM
- → Milestone changed from 0.9.7 to 0.9.9
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 »
