#397 open
Carl Lerche

#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

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 »

Shared Ticket Bins