rails/rails — Issue #4940: An Engine should know about the path where it is mounted
Author: cpetschnig
Created: 2012-02-08 12:38:21+00:00
State: open

This is an example for using the paperclip gem inside an engine:

module MyEngine
class MyAttachment < ActiveRecord::Base
has_attached_file :document, :styles => { :thumb => "100x100>" },
:url => "/document/:id/:style.:extension" # need to know, where the main_app mounted me!
end
end

This code should provide the information:

class Rails::Engine
def self.mounted_path
route = Rails.application.routes.routes.detect do |route|
route.app == self
end
route && route.path
end
end

Should I make a pull request out of that?