aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/lib/action_dispatch/routing
Commit message (Collapse)AuthorAgeFilesLines
* Enable `Layout/EmptyLinesAroundAccessModifier` copRyuta Kamizono2019-06-135-10/+0
| | | | | | | | | | | We sometimes say "✂️ newline after `private`" in a code review (e.g. https://github.com/rails/rails/pull/18546#discussion_r23188776, https://github.com/rails/rails/pull/34832#discussion_r244847195). Now `Layout/EmptyLinesAroundAccessModifier` cop have new enforced style `EnforcedStyle: only_before` (https://github.com/rubocop-hq/rubocop/pull/7059). That cop and enforced style will reduce the our code review cost.
* Use keyword arguments for ActionDispatch::Routing::Mapper::Mapping constructorAlberto Almagro2019-05-221-14/+17
| | | | | | | | | | This commit changes from constructor's argument list to keyword arguments in order to remove the dependency of remember parameters' positions. It also unifies all parameters extracted from the `scope` into `scope_params`, which also takes care of providing the default values for them.
* Use keyword arguments for ActionDispatch::Journey:Route constructorAlberto Almagro2019-05-221-2/+4
| | | | | | | | | | This commit changes from constructor's argument list to keyword arguments in order to remove the dependency of remember parameters' positions. The constructor already provided a default value for `internal`, this commits takes the chance to also add default values for `precedence` and `scope_options`.
* Keep part when scope option has valueAlberto Almagro2019-05-221-6/+7
| | | | | | | | | When a route was defined within an optional scope, if that route didn't take parameters the scope was lost when using path helpers. This patch ensures scope is kept both when the route takes parameters or when it doesn't. Fixes #33219
* Change the deprecation message for dynamic routes segment to 6.1Abhay Nikam2019-04-201-2/+2
|
* Simplify and fasten NamedRouteCollection#define_url_helperJean Boussier2019-04-101-12/+10
|
* Deduplicate strings held by the routerJean Boussier2019-04-031-3/+7
|
* [ci skip] Doc for shallow: false options should use <tt> for better ↵Abhay Nikam2019-04-031-1/+1
| | | | readability. PR after #24405
* Merge pull request #24405 from waits/shallow-falseRafael França2019-04-021-1/+4
|\ | | | | Honor shallow: false on nested resources
| * Honor shallow: false on nested resourcesDylan Waits2016-04-031-1/+4
| | | | | | | | | | | | | | | | Previously there was no way to place a non-shallow resource inside a parent with `shallow: true` set. Now you can set `shallow: false` on a nested child resource to generate normal (non-shallow) routes for it. Fixes #23890.
* | url -> URL where apt inside actionpack/Sharang Dashputre2019-04-011-1/+1
| |
* | Raise if resource custom params contain colonsJosua Schmid2019-03-261-0/+4
| | | | | | | | | | | | | | | | | | | | | | After this change it's not possible anymore to configure routes like this: routes.draw do resources :users, param: "name/:sneaky" end Fixes #30467.
* | Add documentation for the resource(s) :param optionJeff Wallace2019-02-211-0/+3
| |
* | Revert "Don't handle params option in a special way in url_for helper"Rafael Mendonça França2019-01-162-0/+5
| | | | | | | | | | | | | | | | | | | | | | This reverts commit e385e4678fc64be6e176c3bdac6641db9fe48d85. While this option was undocumented it exists to make possible to pass parameters to the route helpers that are reserved like `:domain`. While `url_for(domain: 'foo.com')` would generate a URL in the `foo.com` domain `url_for(params: { domain: 'foo.com' })` would generate a URL with `?domain=foo.com`.
* | Module#{define_method,alias_method,undef_method,remove_method} become public ↵Ryuta Kamizono2018-12-211-4/+4
| | | | | | | | | | | | since Ruby 2.5 https://bugs.ruby-lang.org/issues/14133
* | Remove unnecessary variable routeAlberto Almagro2018-12-021-11/+2
| | | | | | | | | | The variable `route` was only allocated to hold an object that was immediately returned. This patch removes that variable.
* | Raise an error on root route naming conflicts.Gannon McGibbon2018-11-201-4/+2
| | | | | | | | | | Raises an ArgumentError when multiple root routes are defined in the same context instead of assigning nil names to subsequent roots.
* | Merge pull request #20865 from colavitam/only-except-behaviorRafael Mendonça França2018-11-191-2/+8
|\ \ | | | | | | | | | :only and :except are now chained for routing resource(s)
| * | :only and :except are now chained for routing resource(s)Michael Colavita2015-07-131-3/+9
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Allow chaining the :only and :except options for routing resource(s). Previously, the following yielded routes for both show and destroy: resource :account, :only => [:show, :destroy], :except => :destroy This now yields only the show action. This chaining can be useful for passing optional :except options to code that makes use of the :only option (e.g. for a gem with its own routing methods).
* | | Follow up #34064bogdanvlviv2018-10-061-21/+0
| | | | | | | | | | | | | | | | | | | | | | | | | | | The removed code was added in 7f870a5ba2aa9177aa4a0e03a9d027928ba60e49, then 7f870a5ba2aa9177aa4a0e03a9d027928ba60e49 was reverted by #34064. But I found that that commit wasn't completely reverted, I guess it was caused by resolving some conflicts during reverting. @schneems could you please confirm that those changes weren't reverted unintentionally, or reject this commit otherwise?
* | | Revert "Merge pull request #33970 from rails/eager-url-helpers"schneems2018-10-032-20/+4
| | | | | | | | | | | | | | | | | | | | | Until #34050 can be resolved This reverts commit 7f870a5ba2aa9177aa4a0e03a9d027928ba60e49, reversing changes made to 6556898884d636c59baae008e42783b8d3e16440.
* | | Fix call sitesGannon McGibbon2018-10-021-1/+1
| | |
* | | Merge pull request #33256 from ilkkao/ilkkao/remove-unused-params-optionRyuta Kamizono2018-10-011-4/+0
|\ \ \ | | | | | | | | | | | | Don't handle params option in a special way in url_for helper
| * | | Don't handle params option in a special way in url_for helperIlkka Oksanen2018-08-201-4/+0
| | | |
* | | | Add `Style/RedundantFreeze` to remove redudant `.freeze`Yasuo Honda2018-09-293-5/+5
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Since Rails 6.0 will support Ruby 2.4.1 or higher `# frozen_string_literal: true` magic comment is enough to make string object frozen. This magic comment is enabled by `Style/FrozenStringLiteralComment` cop. * Exclude these files not to auto correct false positive `Regexp#freeze` - 'actionpack/lib/action_dispatch/journey/router/utils.rb' - 'activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb' It has been fixed by https://github.com/rubocop-hq/rubocop/pull/6333 Once the newer version of RuboCop released and available at Code Climate these exclude entries should be removed. * Replace `String#freeze` with `String#-@` manually if explicit frozen string objects are required - 'actionpack/test/controller/test_case_test.rb' - 'activemodel/test/cases/type/string_test.rb' - 'activesupport/lib/active_support/core_ext/string/strip.rb' - 'activesupport/test/core_ext/string_ext_test.rb' - 'railties/test/generators/actions_test.rb'
* | | | Merge pull request #34002 from gmcgibbon/fix_deeply_nested_scoped_rootRafael França2018-09-271-1/+1
|\ \ \ \ | | | | | | | | | | Fix optionally scoped root route unscoped access
| * | | | Fix optionally scoped root route unscoped accessGannon McGibbon2018-09-271-1/+1
| | | | |
* | | | | Fixing an edge case when using objects as constraintsSimon Courtois2018-09-271-1/+13
|/ / / / | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This PR fixes an issue when the following situation occurs. If you define a class like this class MyConstraint def call(*args) # for some reason this is defined end def matches?(*args) # checking the args end end and try to use it as a constraint get "/", to: "home#show", constraints: MyConstraint.new if its `matches?` method returns `false` there will be an error for the mapper will ask for the constraint arity, thinking it is a proc, lambda or method. This PR checks for the presence of the `arity` method on the constraint calling it only if present, preventing the error while keeping the basic behavior.
* | | | Routes from Engine Railties should not be an infinite loopAaron Patterson2018-09-261-2/+4
| | | |
* | | | Allow helpers to be deferred until the routes have been finalizedAaron Patterson2018-09-251-0/+22
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | ActiveStorage::BaseController subclasses ActionController::Base. ActionController::Base has an "inherited" hook set that includes the routing helpers to any subclass of AC::Base. Since ActiveStorage::BaseController is a subclass of AC::Base, it will get routing helpers included automatically. Unfortunately, when the framework is eagerly loaded, ActiveStorage::BaseController is loaded *before* the applications routes are loaded which means it attempts to include an "in flight" module so it gets an exception. This commit allows a class that's interested in being extended with routing helpers register itself such that when the routes are finalized, it will get the helpers included. If the routes are already finalized, then the helpers get included immediately.
* | | | Eagerly build the routing helper module after routes are committedAaron Patterson2018-09-252-4/+17
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This commit eagerly builds the route helper module after the routes have been drawn and finalized. This allows us to cache the helper module but not have to worry about people accessing the module while route definition is "in-flight", and automatically deals with cache invalidation as the module is regenerated anytime someone redraws the routes. The restriction this commit introduces is that the url helper module can only be accessed *after* the routes are done being drawn. Refs #24554 and #32892
* | | | Enable `Performance/UnfreezeString` copyuuji.yaginuma2018-09-232-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | In Ruby 2.3 or later, `String#+@` is available and `+@` is faster than `dup`. ```ruby # frozen_string_literal: true require "bundler/inline" gemfile(true) do source "https://rubygems.org" gem "benchmark-ips" end Benchmark.ips do |x| x.report('+@') { +"" } x.report('dup') { "".dup } x.compare! end ``` ``` $ ruby -v benchmark.rb ruby 2.5.1p57 (2018-03-29 revision 63029) [x86_64-linux] Warming up -------------------------------------- +@ 282.289k i/100ms dup 187.638k i/100ms Calculating ------------------------------------- +@ 6.775M (± 3.6%) i/s - 33.875M in 5.006253s dup 3.320M (± 2.2%) i/s - 16.700M in 5.032125s Comparison: +@: 6775299.3 i/s dup: 3320400.7 i/s - 2.04x slower ```
* | | | Convert remaining usage of whitelist and blacklistKevin Deisz2018-08-241-2/+2
| | | |
* | | | Fix `rails routes -c` for controller name consists of multiple word.Yoshiyuki Kinjo2018-08-201-1/+1
|/ / /
* | | Enable Start/EndWith and RegexpMatch copsBart de Water2018-07-281-5/+5
| | | | | | | | | | | | | | | In cases where the MatchData object is not used, this provides a speed-up: https://github.com/JuanitoFatas/fast-ruby/#stringmatch-vs-stringmatch-vs-stringstart_withstringend_with-code-start-code-end
* | | Rails guides are now served over httpsPaul McMahon2018-07-243-4/+4
| | | | | | | | | | | | | | | http links will be redirected to the https version, but still better to just directly link to the https version.
* | | Fix Style/RedundantReturn offensesBart de Water2018-04-211-1/+1
| | |
* | | Small doc fixesT.J. Schuck2018-04-021-1/+1
| | | | | | | | | | | | [ci skip]
* | | Make engine check more explicitAndrew White2018-03-251-6/+9
| | | | | | | | | | | | | | | | | | | | | | | | Not everything that responds to `routes` is a Rails engine - for example a Grape API endpoint will have a `routes` method but can't be used with `assert_recognizes` as it doesn't respond to `recognize_path_with_request`. Fixes #32312.
* | | Cache url helpers moduleAndrew White2018-03-211-1/+2
| | | | | | | | | | | | | | | The urls helpers module returned by Rails.application.routes.url_helpers isn't cached so to prevent the cost of building the module cache it locally.
* | | Rely on Rails::Command's help output.Kasper Timm Hansen2018-03-131-26/+21
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | We end up with: ``` Usage: bin/rails routes [options] Options: -c, [--controller=CONTROLLER] # Filter by a specific controller, e.g. PostsController or Admin::PostsController. -g, [--grep=GREP] # Grep routes by a specific pattern. -E, [--expanded], [--no-expanded] # Print routes expanded vertically with parts explained. ``` which does miss the bit about routes being printed in order. Also: * Renames options to ease help output readability, then clarifies each option. * Fixes a bunch of indentation.
* | | Introduce `ActionDispatch::Routing::ConsoleFormatter::Base`bogdanvlviv2018-03-131-41/+34
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | - Create `Base` and inherit `Sheet` and `Expanded` in order to - prevent code duplication. - Remove trailing "\n" for components of `Expanded`. - There is no need for `Expanded#header` to return `@buffer` so return `nil` instead. - Change `no_routes` message "No routes were found for this controller" since if use `-g`, it sounds incorrect. - Display `No routes were found for this controller.` if apply `-c`. - Display `No routes were found for this grep pattern.` if apply `-g`. Related to #32130
* | | Merge pull request #32160 from bogdanvlviv/improve-rails-routes-expandedKasper Timm Hansen2018-03-111-1/+10
|\ \ \ | | | | | | | | Draw line of a route name to the end of row console on `rails routes --expanded`
| * | | Draw line of a route name to the end of row console on `rails routes --expanded`bogdanvlviv2018-03-051-1/+10
| | | | | | | | | | | | | | | | | | | | | | | | | | | | In order to get width of console use `IO::console_size`, See https://ruby-doc.org/stdlib-2.4.1/libdoc/io/console/rdoc/IO.html#method-c-console_size Related to #32130
* | | | Change doc for "polymorphic_path" in polymorphic_routes.rbMahmoud2018-03-091-2/+1
| | | | | | | | | | | | | | | | | | | | The method 'polymorphic_path' is not using 'polymorphic_url' with `routing_type: :path` anymore in polymorphic_routes.rb
* | | | Quote string return values in doc examples [ci skip]Andrew White2018-03-081-2/+2
| | | |
* | | | Add example of maintaining context with `route_for`Andrew White2018-03-081-0/+6
| | | | | | | | | | | | | | | | [ci skip]
* | | | Express `ActionDispatch::Routing::UrlFor#route_for` as public apibogdanvlviv2018-03-071-1/+13
|/ / / | | | | | | | | | | | | | | | | | | | | | | | | This method was added by #28462 but marked as private api. Since `route_for` looks good in pair with `ActionDispatch::Routing::Mapper::CustomUrls#direct` let's make it as public api. We use it in https://github.com/rails/rails/blob/e83575ff533690db86c92447a539d76b648e9fed/activestorage/config/routes.rb Closes #31417
* | | `ConsoleFormatter` is no longer used as a classRyuta Kamizono2018-03-021-2/+2
| | | | | | | | | | | | It is used as a namespace for `Sheet` and `Expanded`.
* | | Add --expanded option to "rails routes"Benoit Tigeot2018-02-281-37/+90
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | When using rails routes with small terminal or complicated routes it can be very difficult to understand where is the element listed in header. psql had the same issue, that's why they created "expanded mode" you can switch using `\x` or by starting psql with ``` -x --expanded Turn on the expanded table formatting mode. This is equivalent to the \x command. ``` The output is similar to one implemented here for rails routes: db_user-# \du List of roles -[ RECORD 1 ]---------------------------------------------- Role name | super Attributes | Superuser, Create role, Create DB Member of | {} -[ RECORD 2 ]---------------------------------------------- Role name | role Attributes | Superuser, Create role, Create DB, Replication Member of | {}