1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00
Commit graph

27 commits

Author SHA1 Message Date
Aaron Patterson
acb371ca3f call the routes method on engines
if we access the instance, we can free up lots of codes
2014-08-05 16:50:50 -07:00
Aaron Patterson
9a36fac810 a rails application should be an engine subclass 2014-08-05 16:30:08 -07:00
Aaron Patterson
70673759a0 no reason to lazily instantiate the routes
especially if you're just going to add a call two lines down that
populates the cache. common.
2014-08-05 16:28:55 -07:00
Aaron Patterson
ed180eea48 just assign the instance variables on the test 2014-08-05 09:51:47 -07:00
Aaron Patterson
4a7b95985f Rails-ish apps should descend from Rails::Railtie
Use an is_a check to ensure it's a Railsish app so we can avoid
respond_to calls everywhere.
2014-07-16 15:41:47 -07:00
Aaron Patterson
3d9bd2ac94 this class is a model, so it should act like one 2014-05-12 15:54:46 -07:00
Andrew White
b64bac489c Allow engine root relative redirects using an empty string.
Example:

    # application routes.rb
    mount BlogEngine => '/blog'

    # engine routes.rb
    get '/welcome' => redirect('')

This now redirects to the path `/blog`, whereas before it would redirect
to the application root path. In the case of a path redirect or a custom
redirect if the path returned contains a host then the path is treated as
absolute. Similarly for option redirects, if the options hash returned
contains a `:host` or `:domain` key then the path is treated as absolute.

Fixes #7977
2014-01-01 11:19:14 +00:00
Andrew White
9dbd208562 Respect SCRIPT_NAME when using redirect with a relative path
Example:
    # application routes.rb
    mount BlogEngine => '/blog'

    # engine routes.rb
    get '/admin' => redirect('admin/dashboard')

This now redirects to the path `/blog/admin/dashboard`, whereas before it
would've generated an invalid url because there would be no slash between
the host name and the path. It also allows redirects to work where the
application is deployed to a subdirectory of a website.

Fixes #7977
2013-10-10 13:03:26 +01:00
Yves Senn
88ba1fb03e test case to lock down the behavior of #7842 2012-11-04 15:15:29 +01:00
Sam Pohlenz
a79f8bd252 Use internal instance variable naming scheme for mounted URL helper proxies 2012-09-09 16:29:21 +09:30
Piotr Sarnacki
5b3bb61f3f Fix handling SCRIPT_NAME from within mounted engine's
When you mount your application at a path, for example /myapp, server
should set SCRIPT_NAME to /myapp. With such information, rails
application knows that it's mounted at /myapp path and it should generate
routes relative to that path.

Before this patch, rails handled SCRIPT_NAME correctly only for regular
apps, but it failed to do it for mounted engines. The solution was to
hardcode default_url_options[:script_name], which is not the best answer
- it will work only when application is mounted at a fixed path.

This patch fixes the situation by respecting original value of
SCRIPT_NAME when generating application's routes from engine and the
other way round - when you generate engine's routes from application.

This is done by using one of 2 pieces of information in env - current
SCRIPT_NAME or SCRIPT_NAME for a corresponding router. This is because
we have 2 cases to handle:

- generating engine's route from application: in this situation
  SCRIPT_NAME is basically SCRIPT_NAME set by the server and it
  indicates the place where application is mounted, so we can just pass
  it as :original_script_name in url_options. :original_script_name is
  used because if we use :script_name, router will ignore generating
  prefix for engine

- generating application's route from engine: in this situation we
  already lost information about the SCRIPT_NAME that server used. For
  example if application is mounted at /myapp and engine is mounted at
  /blog, at this point SCRIPT_NAME is equal /myapp/blog. Because of that
  we need to keep reference to /myapp SCRIPT_NAME by binding it to the
  current router. Later on we can extract it and use when generating url

Please note that starting from now you *should not* use
default_url_options[:script_name] explicitly if your server already
passes correct SCRIPT_NAME to rack env.

(closes #6933)
2012-08-11 00:21:46 +02:00
Jose and Yehuda
56cdc81c08 Remove default match without specified method
In the current router DSL, using the +match+ DSL
method will match all verbs for the path to the
specified endpoint.

In the vast majority of cases, people are
currently using +match+ when they actually mean
+get+. This introduces security implications.

This commit disallows calling +match+ without
an HTTP verb constraint by default. To explicitly
match all verbs, this commit also adds a
:via => :all option to +match+.

Closes #5964
2012-04-24 22:52:26 -05:00
José Valim
180edc84f1 Override respond_to? since we are also overriding method_missing. 2012-01-03 20:26:45 +01:00
thedarkone
036f77574d Make polymorphic_url calls go through application helpers again.
This brings back the ability to overwrite/extend url generating methods in application heleprs.
2011-07-25 13:43:02 +02:00
Piotr Sarnacki
f545a5081e Fix tests, main_app mounted helper must be defined explicitly now. 2011-04-25 17:57:52 +02:00
Piotr Sarnacki
22b11a41cc Allow mounting engines at '/'
Without that commit script_name always become '/', which
results in paths like //posts/1 instead of /posts/1
2010-09-30 09:47:05 +02:00
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