Rails.env? And Rails.path_to
Join the DZone community and get the full member experience.Join For Free
Until these are added to core... BTW: I think I stole these from Merb, so shout out to the REAL winner of the Rails vs. Merb tit for tat.
if defined? Rails # Example: Rails.env? :development def Rails.env? name Rails.env == name.to_s end # Example: Rails.path_to :public, :images # Returns nil if no dirs passed to it, false if the directory does not exist def Rails.path_to *dirs unless dirs.empty? File.exists?(dir = File.join(Rails.root, *dirs.map(&:to_s))) && dir end end endNote, just stick them in an initializer or lib file. Also note that you might not want to do this, some people despise this sort of thing.
Opinions expressed by DZone contributors are their own.