aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/lib/abstract_controller
Commit message (Collapse)AuthorAgeFilesLines
* Add `Vary: Accept` header when renderingst00122019-07-261-0/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Problem description (quoted from @rafaelfranca's excellent explanation in https://github.com/rails/jquery-ujs/issues/318#issuecomment-88129005): > Let say that we requested /tasks/1 using Ajax, and the previous page has the same url. When we click the back button the browser tries to get the response from its cache and it gets the javascript response. With vary we "fix" this behavior because we are telling the browser that the url is the same but it is not from the same type what will skip the cache. And there's a Rails issue discussing about this problem as well https://github.com/rails/rails/issues/25842 Also, according to [RFC 7231 7.1.4](https://tools.ietf.org/html/rfc7231#section-7.1.4) > An origin server SHOULD send a Vary header field when its algorithm > for selecting a representation varies based on aspects of the request > message other than the method and request target we should add `Vary: Accept` header when determining content based on the `Accept` header. Although adding such header by default could cause unnecessary cache invalidation. But this PR only adds the header if: - The format param is not provided - The request is a `xhr` request - The request has accept headers and the headers are valid So if the user - sends request with explicit format, like `/users/1.json` - or sends a normal request (non xhr) - or doesn't specify accept headers then the header won't be added. See the discussion in https://github.com/rails/rails/issues/25842 and https://github.com/rails/rails/pull/36213 for more details.
* Enable `Layout/EmptyLinesAroundAccessModifier` copRyuta Kamizono2019-06-132-2/+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 file/line from call to helper_moduleJohn Hawthorn2019-06-031-5/+10
|
* Give HelperMethods module a nameJohn Hawthorn2019-06-031-2/+13
|
* AbstractController::Translation#t: dup optionsNazar Matus2019-02-151-0/+1
|
* Remove unused codebogdanvlviv2019-01-301-1/+0
| | | | | | | | - Remove `fragment_cache_key` helper declaration. It was removed in e70d3df7c9b05c129b0fdcca57f66eca316c5cfc - Remove `by_private_lifo`. It is unused since a7becf147afc85c354e5cfa519911a948d25fc4d
* Remove deprecated `fragment_cache_key` helper in favor of ↵Rafael Mendonça França2019-01-171-19/+0
| | | | `combined_fragment_cache_key`
* Don't use deprecated `Module#parents`yuuji.yaginuma2018-10-051-1/+1
|
* Revert "Merge pull request #33970 from rails/eager-url-helpers"schneems2018-10-031-2/+5
| | | | | | | Until #34050 can be resolved This reverts commit 7f870a5ba2aa9177aa4a0e03a9d027928ba60e49, reversing changes made to 6556898884d636c59baae008e42783b8d3e16440.
* Add `Style/RedundantFreeze` to remove redudant `.freeze`Yasuo Honda2018-09-292-2/+2
| | | | | | | | | | | | | | | | | | | | | 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'
* Allow helpers to be deferred until the routes have been finalizedAaron Patterson2018-09-251-5/+2
| | | | | | | | | | | | | | | | 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.
* Fewer allocations in caching/fragments.rbschneems2018-08-291-1/+5
| | | | Instead of using a splat on the head and tail we can mutate the array by flattening 1 level. We get further savings by not allocating another via `compact` but instead by using `compact!`
* Remove extra execution of `uniq!` on action_methodsbogdanvlviv2018-08-221-1/+0
| | | | | | Execution of `to_set` below should remove duplicated elements. Follow up #33693
* Two fewer array allocations on action_methodsschneems2018-08-221-1/+4
| | | | Instead of creating new arrays for `uniq` and `map` we can instead modify the array in place.
* Show the `ENV` value correctly in the doc of `combined_fragment_cache_key` ↵yuuji.yaginuma2018-08-221-1/+1
| | | | | | | [ci skip] It seems to need an escape for the showing `ENV`. https://api.rubyonrails.org/classes/AbstractController/Caching/Fragments.html#method-i-combined_fragment_cache_key
* Enable Start/EndWith and RegexpMatch copsBart de Water2018-07-281-1/+1
| | | | | 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-241-1/+1
| | | | | http links will be redirected to the https version, but still better to just directly link to the https version.
* Add cancellation info to before filter docsZachary Wasserman2018-03-141-0/+12
| | | | | | | | | It is important for users to know that a render or redirect in a "before" filter causes the action to be cancelled. This was addressed in the guide, but not the API docs (http://guides.rubyonrails.org/action_controller_overview.html#filters). [ci skip]
* [Action Pack] require => require_relativeAkira Matsuda2017-10-212-2/+2
| | | | | This basically reverts e9fca7668b9eba82bcc832cb0061459703368397, d08da958b9ae17d4bbe4c9d7db497ece2450db5f, d1fe1dcf8ab1c0210a37c2a78c1ee52cf199a66d, and 68eaf7b4d5f2bb56d939f71c5ece2d61cf6680a3
* Keep `:api: plugin` methods in the doc [ci skip]Ryuta Kamizono2017-10-201-3/+3
| | | | | | | `:api:` tag was removed in 5349f231 since RDoc doesn't support `:api:` tag. But those methods are not private API, they are public API for renderers. The renderers should be able to know that they can override this method.
* Make internal methods in `AbstractController::Rendering` to privateRyuta Kamizono2017-10-021-0/+1
|
* Remove `:api:` tag that has leaked on the doc directly [ci skip]Ryuta Kamizono2017-09-302-15/+3
| | | | | | | | | | | | Currently `:api:` tag has leaked on the doc directly since RDoc doesn't support `:api:` tag directive. http://api.rubyonrails.org/v5.1/classes/AbstractController/Rendering.html So `:api: private` doesn't work as expected. We are using `:nodoc:` for the purpose. Related #13989.
* Replace unnecessary link with typewriter text [ci skip]Yoshiyuki Hirano2017-09-021-2/+2
|
* Use frozen string literal in actionpack/Kir Shatrov2017-07-2913-0/+26
|
* [Abstract Controller] require => require_relativeAkira Matsuda2017-07-012-2/+2
|
* Remove useless class checking for `ActiveSupport::Callbacks`s result_lambdafatkodima2017-06-271-1/+1
|
* Allow translate default option to accept an array similar to i18n.t. Fixes ↵Vipul A M2017-06-151-1/+1
| | | | #29441
* Add option for class_attribute default (#29270)David Heinemeier Hansson2017-05-292-7/+3
| | | | | | | | | | | | * Allow a default value to be declared for class_attribute * Convert to using class_attribute default rather than explicit setter * Removed instance_accessor option by mistake * False is a valid default value * Documentation
* Merge pull request #29072 from ↵Robin Dupret2017-05-211-0/+20
|\ | | | | | | | | dixpac/dixpac/add_documentation_for_validate_and_callback_order_of_execution Improving docs for callbacks execution order [ci skip]
| * Improving docs for callbacks execution order [ci skip]dixpac2017-05-211-0/+20
| | | | | | | | | | When define callbacks latest definition on the same callback/method overwrites previous ones.
* | Merge pull request #29134 from joshaidan/document-action-nameAlex Kitchens2017-05-191-0/+8
|\ \ | | | | | | Add documentation to accessors in AbstractController::Base
| * | Clarified description of formats [ci skip]Brian Jones2017-05-191-1/+1
| | |
| * | Added missing punctuation [ci skip]Brian Jones2017-05-181-3/+3
| | |
| * | Specify only the body of the response is returned [ci skip]Brian Jones2017-05-181-1/+1
| | |
| * | Document accessors response_body, action_name, formats [ci skip]Brian Jones2017-05-171-0/+8
| |/
* / Use recyclable cache keys (#29092)David Heinemeier Hansson2017-05-181-7/+28
|/
* Unfreeze interpolated string because it's useless.Stan Lo2017-02-191-1/+1
|
* Freeze fragment cache related instrument name.Stan Lo2017-02-071-1/+1
| | | | | | | | | | | | | ActionMailer::Base#instrument_name and ActionController::Base#instrument_name will be frequently called once caching is enabled. So it's better to freeze them instead of create new string on every call. Also, the instrument name in #instrument_fragment_cache will usually be "write_fragment.action_controller" or "read_fragment.action_controller". So freezing them might also gain some performance improvement. We have done something like this in other places: https://github.com/rails/rails/blob/master/actionview/lib/action_view/template.rb#L348
* Change ActionView ERB Handler from Erubis to ErubiJeremy Evans2017-01-251-2/+0
| | | | | | | | | | | | | | | | | | | | | | | Erubi offers the following advantages for Rails: * Works with ruby's --enable-frozen-string-literal option * Has 88% smaller memory footprint * Does no freedom patching (Erubis adds a method to Kernel) * Has simpler internals (1 file, <150 lines of code) * Has an open development model (Erubis doesn't have a public source control repository or bug tracker) * Is not dead (Erubis hasn't been updated since 2011) Erubi is a simplified fork of Erubis that contains just the parts that are generally needed (which includes the parts that Rails uses). The only intentional difference in behavior is that it does not include support for <%=== tags for debug output. That could be added to the ActionView ERB handler if it is desired. The Erubis template handler remains in a deprecated state so that code that accesses it directly does not break. It can be removed after Rails 5.1.
* Extract variant setter to process methodJon Moss2017-01-021-4/+4
| | | | | | | Provide an API interface similar to how format is handled in Controllers. In situations where variants are not needed (ex: in Action Mailer) the method will simply trigger a no-op, and will not affect end users.
* Privatize unneededly protected methods in Action PackAkira Matsuda2016-12-242-3/+3
|
* Merge pull request #26905 from bogdanvlviv/docsAndrew White2016-11-131-4/+4
|\ | | | | Add missing `+` around a some literals.
| * Add missing `+` around a some literals.bogdanvlviv2016-10-271-4/+4
| | | | | | | | | | | | Mainly around `nil` [ci skip]
* | Add more rubocop rules about whitespacesRafael Mendonça França2016-10-291-1/+1
| |
* | removes requires already present in active_support/railsXavier Noria2016-10-271-2/+0
|/
* Remove deprecated methods related to controller filtersRafael Mendonça França2016-10-091-39/+0
| | | | | | | | | | `skip_action_callback`, `skip_filter`, `before_filter`, `prepend_before_filter`, `skip_before_filter`, `append_before_filter`, `around_filter` `prepend_around_filter`, `skip_around_filter`, `append_around_filter`, `after_filter`, `prepend_after_filter`, `skip_after_filter` and `append_after_filter`.
* Fix broken comments indentation caused by rubocop auto-correct [ci skip]Ryuta Kamizono2016-09-141-6/+6
| | | | | | All indentation was normalized by rubocop auto-correct at 80e66cc4d90bf8c15d1a5f6e3152e90147f00772. But comments was still kept absolute position. This commit aligns comments with method definitions for consistency.
* Add three new rubocop rulesRafael Mendonça França2016-08-162-2/+2
| | | | | | | | Style/SpaceBeforeBlockBraces Style/SpaceInsideBlockBraces Style/SpaceInsideHashLiteralBraces Fix all violations in the repository.
* code gardening: removes redundant selfsXavier Noria2016-08-081-1/+1
| | | | | | | | | A few have been left for aesthetic reasons, but have made a pass and removed most of them. Note that if the method `foo` returns an array, `foo << 1` is a regular push, nothing to do with assignments, so no self required.
* Modify LogSubscriber for single partial's cache message.Stan Lo2016-08-081-0/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Implement naive partial caching mechanism. Add test for LogSubscriber Use ActionView::Base#log_payload to store log_subscriber's payload, so we can pass cache result into it. Fixed tests Remove useless settings Check if #log_payload exists before calling it. Because other classes also includes CacheHelper but don't have is attribute Use @log_payload_for_partial_reder instead of #log_payload to carry ActionView's payload. Update test's hash syntax Add configuration to enable/disable fragment caching logging Remove unless test and add new test to ensure cache info won't effect next rendering's log Move :enable_fragment_cache_logging config from ActionView to ActionPack Apply new config to tests Update actionview's changelog Update configuration guide Improve actionview's changelog Refactor PartialRenderer#render and log tests Mute subscriber's log instead of disabling instrumentation. Fix typo, remove useless comment and use new hash syntax Improve actionpack's log_subscriber test Fix rebase mistake Apply new config to all caching intstrument actions