Skip to content
This repository
Browse code

Documented mounted helpers

  • Loading branch information...
commit 434139f89fd2ec550b8c5ab1309e5a8af06142d7 1 parent 1a161c7
Piotr Sarnacki authored August 04, 2010

Showing 1 changed file with 29 additions and 0 deletions. Show diff stats Hide diff stats

  1. 29  railties/lib/rails/engine.rb
29  railties/lib/rails/engine.rb
@@ -208,6 +208,35 @@ module Rails
208 208
   # MyEngine::Engine.engine_name #=> "my_engine"
209 209
   # and it will set MyEngine.table_name_prefix to "my_engine_"
210 210
   #
  211
+  # == Using Engine's routes outside Engine
  212
+  #
  213
+  # Since you can mount engine inside application's routes now, you do not have direct access to engine's
  214
+  # url_helpers inside application. When you mount Engine in application's routes special helper is
  215
+  # created to allow doing that. Consider such scenario:
  216
+  #
  217
+  # # APP/config/routes.rb
  218
+  # MyApplication::Application.routes.draw do
  219
+  #   mount MyEngine::Engine => "/my_engine", :as => "my_engine"
  220
+  #   match "/foo" => "foo#index"
  221
+  # end
  222
+  #
  223
+  # Now, you can use my_engine helper:
  224
+  #
  225
+  # class FooController < ApplicationController
  226
+  #   def index
  227
+  #     my_engine.root_url #=> /my_engine/
  228
+  #   end
  229
+  # end
  230
+  #
  231
+  # There is also 'app' helper that gives you access to application's routes inside Engine:
  232
+  #
  233
+  # module MyEngine
  234
+  #   class BarController
  235
+  #     app.foo_path #=> /foo
  236
+  #   end
  237
+  # end
  238
+  #
  239
+  # Note that :as option takes engine_name as default, so most of the time you can ommit it.
211 240
   class Engine < Railtie
212 241
     autoload :Configurable,  "rails/engine/configurable"
213 242
     autoload :Configuration, "rails/engine/configuration"

0 notes on commit 434139f

Please sign in to comment.
Something went wrong with that request. Please try again.