aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/lib/action_dispatch/routing
Commit message (Collapse)AuthorAgeFilesLines
* Merge pull request #23103 from rails/refactor-handling-of-action-defaultJeremy Daer2016-04-243-16/+6
|\ | | | | | | Refactor handling of :action default in routing
| * Refactor handling of :action default in routingAndrew White2016-02-163-16/+6
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The longstanding convention in Rails is that if the :action parameter is missing or nil then it defaults to 'index'. Up until Rails 5.0.0.beta1 this was handled slightly differently than other routing defaults by deleting it from the route options and adding it to the recall parameters. With the recent focus of removing unnecessary duplications this has exposed a problem in this strategy - we are now mutating the request's path parameters and causing problems for later url generation. This will typically affect url_for rather a named url helper since the latter explicitly pass :controller, :action, etc. The fix is to add a default for :action in the route class if the path contains an :action segment and no default is passed. This change also revealed an issue with the parameterized part expiry in that it doesn't follow a right to left order - as soon as a dynamic segment is required then all other segments become required. Fixes #23019.
* | Merge pull request #24031 from ↵Jeremy Daer2016-04-191-2/+1
|\ \ | | | | | | | | | | | | | | | samphilipd/sam/do_not_clobber_options_in_route_definitions Do not destructively mutate passed options hash in route definitions
| * | Do not destructively mutate passed options hash in route definitionsSam Davies2016-03-031-2/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | - Fixes #24030 An example scope might be specified as such: ```ruby HTML = { constraints: { format: :html } }.freeze scope HTML do get 'x' end ``` This currently raises an error because the mapper attempts to destructively modify the passed options hash. This is dangerous because this options hash might even be shared with other scopes. We should instead always instantiate a new object instead of modifying the passed options.
* | | Pass over all Rails 5 warnings, to make sure:Vipul A M2016-04-122-3/+3
|/ / | | | | | | | | | | | | | | | | | | - we are ending sentences properly - fixing of space issues - fixed continuity issues in some sentences. Reverts https://github.com/rails/rails/commit/8fc97d198ef31c1d7a4b9b849b96fc08a667fb02 . This change reverts making sure we add '.' at end of deprecation sentences. This is to keep sentences within Rails itself consistent and with a '.' at the end.
* | Niceify the dynamic routes deprecation messagesJon Atack2016-03-031-2/+8
| | | | | | | | | | | | | | | | | | | | Follow-up to #23980. - Fix grammar: "be remove" -> "be removed". - Wrap lines at 80 chars. Lurvely ;-)
* | Deprecate :controller and :action path parametersAndrew White2016-03-011-0/+9
| | | | | | | | | | | | | | | | Allowing :controller and :action values to be specified via the path in config/routes.rb has been an underlying cause of a number of issues in Rails that have resulted in security releases. In light of this it's better that controllers and actions are explicitly whitelisted rather than trying to blacklist or sanitize 'bad' values.
* | [ci skip] Replace usage of rake routes with rails routesAbhishek Jain2016-02-251-1/+1
| |
* | Add `internal` attribute to routesJon Moss2016-02-222-2/+4
|/ | | | | | | | | | | | | | This is meant to provide a way for Action Cable, Sprockets, and possibly other Rack applications to mark themselves as internal, and to exclude themselves from the routing inspector, and thus `rails routes` / `rake routes`. I think this is the only way to have mounted Rack apps be marked as internal, within AD/Journey. Another option would be to create an array of regexes for internal apps, and then to iterate over that everytime a request comes through. Also, I only had the first `add_route` method set `internal`'s default to false, to avoid littering it all over the codebase.
* Use a URL instead of an URL everywhereAbhishek Jain2016-02-152-2/+2
|
* Fixes routes to match verbs and path with -g optionAbhishek Jain2016-02-111-2/+3
|
* Converge on filter.Kasper Timm Hansen2016-02-011-5/+4
| | | | | | | | Some places were saying filter, while others said filter_options, spare the ambiguity and use filter throughout. This inlines a needless local variable and clarifies a route filter consists of defaults and values to match against.
* Simplify filter normalization.Kasper Timm Hansen2016-02-011-5/+3
| | | | | | | Assume the filter is a string, if it wasn't a hash and isn't nil. Remove needless else and rely on Ruby's default nil return. Add spaces within hash braces.
* Add options for rake routes taskVipul A M2016-02-021-15/+19
| | | | | | | | | | Add two options: `-c` and `-g`. `-g` option returns the urls name, verb and path fields that match the pattern. `-c` option returns the urls for specific controller. Fixes #18902, and Fixes #20420 [Anton Davydov & Vipul A M]
* Fix marking of custom routes for JourneyAndrew White2016-01-201-14/+20
| | | | | | | | | | | | The Mapper build_path method marks routes where path parameters are part of a path segment as custom routes by altering the regular expression, e.g: get '/foo-:bar', to: 'foo#bar' There were some edge cases where certain constructs weren't being picked up and this commit fixes those. Fixes #23069.
* Revert "Remove literal? check to fix issue with prefixed optionals"eileencodes2016-01-201-1/+1
| | | | | | | | | This reverts commit 5d1b7c3b441654e8008dcd303f5367883ec660a6. The change here didn't actually fix the issue it was trying to fix, and this isn't the correct way to fix either issue. The problem is switching from the builder to grouping with find_all/regex is now very dependent on how you structure your path pattern.
* Remove literal? check to fix issue with prefixed optionalseileencodes2016-01-161-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | In commit d993cb3 `build_path` was changed from using `grep` to `find_all` to save array allocations. This change was a little too aggressive in that when the dash comes before the symbol like `/omg-:song` the symbol is skipped. Removing the check for `n.right.left.literal?` fixes this issue, but does add back some allocations. The number of allocations are still well less than before. I've added a regression test to test this behavior for the future. Fixes #23069. Array allocations as of d993cb3: ``` {:T_SYMBOL=>11} {:T_REGEXP=>17} {:T_STRUCT=>6500} {:T_MATCH=>12004} {:T_OBJECT=>91009} {:T_DATA=>100088} {:T_HASH=>114013} {:T_STRING=>159637} {:T_ARRAY=>321056} {:T_IMEMO=>351133} ``` Array allocations after this change: ``` {:T_SYMBOL=>11} {:T_REGEXP=>1017} {:T_STRUCT=>6500} {:T_MATCH=>12004} {:T_DATA=>84092} {:T_OBJECT=>87009} {:T_HASH=>110015} {:T_STRING=>166152} {:T_ARRAY=>322056} {:T_NODE=>343558} ```
* Better error message when running `rake routes` with CONTROLLER arg:Edouard CHIN2016-01-071-7/+18
| | | | | | | - `CONTROLLER` argument can now be supplied in different ways (Rails::WelcomeController, Rails::Welcome, rails/welcome) - If `CONTROLLER` argument was supplied but it does not exist, will warn the user that this controller does not exist - If `CONTROLLER` argument was supplied and no routes could be found matching this filter, will warn the user that no routes were found matching the supplied filter - If no routes were defined in the config/routes.rb file, will warn the user with the original message
* Merge pull request #20109 from prathamesh-sonpatki/keep-only-one-rootKasper Timm Hansen2016-01-071-21/+21
|\ | | | | Remove original root method from Base module and kept overridden implementation in Resources module.
| * Kept overridden root method and removed original methodPrathamesh Sonpatki2016-01-071-21/+21
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | - The root method is defined and documented in Base module and decorated in Resources module. - The documentation in Base module actually talks about method signature of decorated method from Resources module. - Argument handling was moved to decorated method in https://github.com/rails/rails/commit/977455cc2efb94f40b4c0d46d1842be198ed7c4c to handle options such as :as with directly passed path parameter. - To avoid the confusion, removed original root method from Base module and only kept overridden version in Resources module. - References - https://github.com/rails/rails/pull/12208 & https://github.com/rails/rails/pull/12208#issuecomment-24350897.
* | Allow AC::Parameters as an argument to url_helpersPrathamesh Sonpatki2016-01-071-2/+11
| | | | | | | | | | | | | | | | - Earlier only Hash was allowed as params argument to url_helpers. - Now ActionController::Parameters instances will also be allowed. - If the params are not secured then it will raise an ArgumentError to indicate that constructing URLs with non-secure params is not recommended. - Fixes #22832.
* | Merge pull request #20797 from byroot/prevent-url-for-ac-parametersRafael França2015-12-181-1/+4
|\ \ | | | | | | Prevent ActionController::Parameters in url_for
| * | Prevent ActionController::Parameters from being passed to url_for directlyJean Boussier2015-12-151-1/+4
| |/
* / Don't catch all NameError to reraise as ActionController::RoutingError #22368Maxime Garcia2015-12-121-2/+4
|/
* Merge pull request #22373 from yui-knk/ad_constraintsYves Senn2015-11-301-1/+1
|\ | | | | Add `Routing` namespace to point appropriate constant
| * Add `Routing` namespace to point appropriate constantyui-knk2015-11-221-1/+1
| | | | | | | | Make it clear we use `ActionDispatch::Routing::Endpoint`
* | Brush up errors of `ActionDispatch::Routing::Mapper#mount`yui-knk2015-11-281-6/+9
|/ | | | | | * Integrate to raise `ArgumentError` * Detailed error message when `path` is not defined * Add a test case, invalid rack app is passed
* Remove arity check for `RouteSet#draw`yui-knk2015-11-211-4/+0
| | | | | This code was added for migration from Rails 3.1 to upper, now we are developing Rails 5.
* remove unnecessary forwardable requireTimo Schilling2015-10-211-1/+0
| | | `Forwardable` has been used in the past
* Delete needless `require 'active_support/deprecation'`yui-knk2015-10-201-1/+0
| | | | | When `require 'active_support/rails'`, 'active_support/deprecation' is automatically loaded.
* Merge pull request #21849 from yui-knk/refactor_regexp_to_stringAndrew White2015-10-121-4/+0
|\ | | | | Change `Journey::Route#verb` to return string instead of regexp.
| * Change `Journey::Route#verb` to return string instead of regexp.yui-knk2015-10-031-4/+0
| | | | | | | | | | | | | | | | | | By [this commit](https://github.com/rails/rails/commit/0b476de445faf330c58255e2ec3eea0f3a7c1bfc) `Journey::Route#verb` need not to return verb as regexp. The returned value is used by inspector, so change it to be a string. Add inspect_with_multiple_verbs test case to keep the behavior of inspector correctly.
* | Allow multiple `root` routes in same scope levelRafael Sales2015-10-101-2/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | When an application has multiple root entries with different constraints, the current solution is to use `get '/'`. Example: **Currently I have to do:** ```ruby get '/', to: 'portfolio#show', constraints: ->(req) { Hostname.portfolio_site?(req.host) } get '/', to: 'blog#show', constraints: ->(req) { Hostname.blog_site?(req.host) } root 'landing#show' ``` **But I would like to do:** ```ruby root 'portfolio#show', constraints: ->(req) { Hostname.portfolio_site?(req.host) } root 'blog#show', constraints: ->(req) { Hostname.blog_site?(req.host) } root 'landing#show' ``` Other URL matchers such as `get`, `post`, etc, already allows this, so I think it's fair that `root` also allow it since it's just a shortcut for a `get` internally.
* | Fix mounted engine named routes regressionMatthew Erhard2015-10-072-2/+7
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | When generating the url for a mounted engine through its proxy, the path should be the sum of three parts: 1. Any `SCRIPT_NAME` request header or the value of `ActionDispatch::Routing::RouteSet#relative_url_root`. 2. A prefix (the engine's mounted path). 3. The path of the named route inside the engine. Since commit https://github.com/rails/rails/commit/44ff0313c121f528a68b3bd21d6c7a96f313e3d3, this has been broken. Step 2 has been changed to: 2. A prefix (the value of `ActionDispatch::Routing::RouteSet#relative_url_root` + the engine's mounted path). The value of `ActionDispatch::Routing::RouteSet#relative_url_root` is taken into account in step 1 of the route generation and should be ignored when generating the mounted engine's prefix in step 2. This commit fixes the regression by having `ActionDispatch::Routing::RouteSet#url_for` check `options[:relative_url_root]` before falling back to `ActionDispatch::Routing::RouteSet#relative_url_root`. The prefix generating code then sets `options[:relative_url_root]` to an empty string. This empty string is used instead of `ActionDispatch::Routing::RouteSet#relative_url_root` and avoids the duplicate `relative_url_root` value in the final result. This resolves #20920 and resolves #21459
* | [ci skip] Change 'an URL' to 'a URL' as URL doesn't have a vowel soundtanmay30112015-10-062-2/+2
|/
* `url_for` does not modify polymorphic optionsBernerd Schaefer2015-09-041-1/+2
| | | | | | | | | | | | | | | | | The `url_for` methods in `actionpack` and `actionview` now make a copy of the provided options before generating polymorphic paths or URLs. The bug in the previous behavior is most noticeable in a case like: url_options = [:new, :post, param: 'value'] if current_page?(url_options) css_class = "active" end link_to "New Post", url_options, class: css_class
* Remove not used requiresMarcin Olichwirowicz2015-09-011-3/+1
|
* provide a request and response to all controllersAaron Patterson2015-08-251-4/+6
| | | | | | | | | | Controllers should always have a request and response when responding. Since we make this The Rule(tm), then controllers don't need to be somewhere in limbo between "asking a response object for a rack response" or "I, myself contain a rack response". This duality leads to conditionals spread through the codebase that we can delete: * https://github.com/rails/rails/blob/85a78d9358aa728298cd020cdc842b55c16f9549/actionpack/lib/action_controller/metal.rb#L221-L223
* adding a direct dispatch method to controller classesAaron Patterson2015-08-251-1/+1
| | | | This saves a lambda and request allocation on each request.
* always dispatch to controllers the same wayAaron Patterson2015-08-252-7/+25
| | | | | controllers should always go through the `action` class method so that their middleware is respected.
* always return a controller class from the `controller_class` methodAaron Patterson2015-08-251-3/+1
| | | | | now the caller can just treat it like a regular controller even though it will return a 404
* pull up dispatcher allocationAaron Patterson2015-08-242-5/+1
| | | | | the dispatcher class isn't configurable anymore, so pull up allocation to the method that needs it.
* directly ask the request for the controller classAaron Patterson2015-08-241-6/+1
| | | | | | Now that we don't have subclasses depending on this method (they augment the request class instead of the dispatch class) we can remove this method and directly ask the request object for the controller class
* remove useless ivarAaron Patterson2015-08-241-2/+1
|
* remove setter for the dispatcher classAaron Patterson2015-08-241-2/+2
| | | | we don't need it anymore. We always use the same dispatcher in tests.
* use a custom request class to determine the controller classAaron Patterson2015-08-241-2/+7
| | | | | | controller class resolution has been moved to the request object, so we should override that method instead of relying on the RouteSet to generate the controller class.
* Remove unused block argumentsdeepj2015-08-231-2/+2
|
* Fix Railties test failure for asset routeseileencodes2015-08-221-1/+5
| | | | | | | | | Since none of the action pack tests failed without this conditional it didn't seem necessary. This fixes the build because it correctly returns a 404 instead of a 500 for the asset routes test. Test that was failing was in the `assets_test.rb` file and was the test named `test_assets_routes_are_not_drawn_when_compilation_is_disabled`.
* Refactor to remove controller class from route to requesteileencodes2015-08-221-40/+8
| | | | | | | | | | This refactoring moves the controller class name that was on the route set to the request. The purpose of this refactoring is for changes we need to move controller tests to integration tests, mainly being able to access the controller on the request instead of having to go through the router. [Eileen M. Uchitelle & Aaron Patterson]
* Remove unnecessary cachingeileencodes2015-08-211-5/+1
| | | | | | | `ActiveSupport::Dependencies.constantize(const_name)` calls `Reference.new` which is defined as `ActiveSupport::Dependencies.constantize(const_name)` meaning this call is already cached and we're doing caching that isn't necessary.