Commit Graph

11 Commits

Author SHA1 Message Date
Piotr Sarnacki
6258f7c972 Change app to main_app in mounted_helpers 2010-09-08 19:27:59 +02:00
Piotr Sarnacki
18aee33335 Do not require passing :app to mounted helpers, it's actually useless and not DRY 2010-09-08 19:27:59 +02:00
Piotr Sarnacki
1e6612ef80 Ensure that url_helpers included after application's ones have higher priority 2010-09-03 22:59:07 +02:00
Piotr Sarnacki
6c95e0f879 Add mounted_helpers to routes
mounted_helpers are a bit similar to url_helpers. They're automatically
included in controllers for Rails.application and each of mounted
Engines. Mounted helper allows to call url_for and named helpers for
given application.

Given Blog::Engine mounted as blog_engine, there are 2 helpers defined:
app and blog_engine. You can call routes for app and engine using those
helpers:

app.root_url
app.url_for(:controller => "foo")
blog_engine.posts_path
blog_engine.url_for(@post)
2010-09-03 22:59:07 +02:00
Piotr Sarnacki
e9791bec82 Routes refactoring:
* added more tests for prefix generation
* fixed bug with generating host for both prefix and url
* refactored url_for method
* organized tests for prefix generation
2010-09-03 22:59:07 +02:00
Piotr Sarnacki
229a868264 Use new url_for API instead of including routes.url_helpers 2010-09-03 22:59:06 +02:00
Piotr Sarnacki
b697ba9fd7 Added some more tests for url generation between Engine and Application 2010-09-03 22:59:06 +02:00
Piotr Sarnacki
b1e5e233fa Refactored tests for prefix generation and added test for url generation in regular class with default_url_options[:script_name] set 2010-09-03 22:59:05 +02:00
Piotr Sarnacki
eedbf87d15 New way of generating urls for Application from Engine.
It's based specifying application's script_name with:
Rails.application.default_url_options = {:script_name => "/foo"}

default_url_options method is delegated to routes. If router
used to generate url differs from the router passed via env
it always overwrites :script_name with this value.
2010-09-03 22:59:05 +02:00
Piotr Sarnacki
451c9942bb Allow to generate Application routes inside Engine
This requires knowledge about original SCRIPT_NAME and
the parent router. It should be pass through the env
as ORIGIAL_SCRIPT_NAME and action_dispatch.parent_routes
2010-09-03 22:59:05 +02:00
Piotr Sarnacki
28016d33b0 Use env['action_dispatch.routes'] to determine if we should generate prefix or not.
This technique is here to allow using routes from Engine in Application
and vice versa. When using Engine routes inside Application it should
generate prefix based on mount point. When using Engine routes inside
Engine it should use env['SCRIPT_NAME']. In any other case it should
generate prefix as env should not be even available.
2010-09-03 22:59:05 +02:00