Rails.root returns a Pathname

Having got quite used to Rails.root returning a Pathname object to allow easy concatenation of paths, I noticed that Rails.public_path doesn’t. I checked in 2.3.5 and master and it’s not in either case.

It seems easy enough to do:

railties/lib/initializer.rb (for 2.3.5):

def public_path

@@public_path ||= Pathname(self.root ? File.join(self.root, “public”) : “public”)

end

railties/lib/rails.rb (for 3.0 beta):

def public_path

@@public_path ||= Pathname(self.root ? File.join(self.root, “public”) : “public”)

end

Am I missing something? Is there a reason for the inconsistency that I’m unaware of?

I’m happy to provide a patch if required, but it’s going to be fairly minimal given the change above is Pathname and two parenthesis :slight_smile:

Cheers,

Andy

I say submit the patch. It sounds to me just like something overlooked.

Just my two cents, leave the method as is with a deprecation notice, and add Rails.public as a Pathname. In Rails 3.1 or something it can be tossed out. There’s enough for people to upgrade already, one more thing isn’t necessary.

-Nick

We’re moving away from global locations for this stuff anyway. Your application object should have a paths object on it with the locations of each conceptual location :slight_smile:

Thanks for your input guys - new ticket/patch created:

https://rails.lighthouseapp.com/projects/8994-ruby-on-rails/tickets/3988-patch

Cheers,

Andy