aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/lib/abstract_controller/base.rb
Commit message (Collapse)AuthorAgeFilesLines
* Add `Style/RedundantFreeze` to remove redudant `.freeze`Yasuo Honda2018-09-291-1/+1
| | | | | | | | | | | | | | | | | | | | | 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'
* 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.
* [Action Pack] require => require_relativeAkira Matsuda2017-10-211-1/+1
| | | | | This basically reverts e9fca7668b9eba82bcc832cb0061459703368397, d08da958b9ae17d4bbe4c9d7db497ece2450db5f, d1fe1dcf8ab1c0210a37c2a78c1ee52cf199a66d, and 68eaf7b4d5f2bb56d939f71c5ece2d61cf6680a3
* Remove `:api:` tag that has leaked on the doc directly [ci skip]Ryuta Kamizono2017-09-301-2/+0
| | | | | | | | | | | | 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.
* Use frozen string literal in actionpack/Kir Shatrov2017-07-291-0/+2
|
* [Abstract Controller] require => require_relativeAkira Matsuda2017-07-011-1/+1
|
* 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
|
* 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.
* Add missing `+` around a some literals.bogdanvlviv2016-10-271-4/+4
| | | | | | Mainly around `nil` [ci skip]
* applies new string literal convention in actionpack/libXavier Noria2016-08-061-7/+7
| | | | | The current code base is not uniform. After some discussion, we have chosen to go with double quotes by default.
* Use `#performed?` to terminate controller callbacksJeff Kreeftmeijer2016-06-031-0/+7
| | | | | | | | | | | | | | | Since 69009f, `ActionController::Metal::DataStreaming#send_file` doesn't set `@_response_body` anymore. `AbstractController::Callbacks` used `@_response_body` in its callback terminator, so it failed to halt the callback cycle when using `#send_file` from a `before_action`. Instead, it now uses `#performed?` on `AbstractController::Base` and `ActionController::Metal`, which checks `response.committed?`, besides checking if `@_response_body` is set, if possible. Example application: https://gist.github.com/jeffkreeftmeijer/78ae4572f36b198e729724b0cf79ef8e
* Revert "Make sure the cache is always populated"Rafael Mendonça França2016-05-201-5/+1
| | | | | | This reverts commit 0ce7eae7418f1b9bb06b351c1f26d50c3674c0d0. Tests were broken https://travis-ci.org/rails/rails/jobs/131850726#L520
* Make sure the cache is always populatedAaron Patterson2016-05-201-1/+5
| | | | This way we don't have to make multiple calls on anonymous controllers
* Actioncable and Actionpack documentation typos [ci skip]Tom Kadwill2016-04-211-1/+1
|
* Break up a circular require between AP/AVSean Griffin2016-03-111-3/+1
| | | | | | | | | | | | | | | | | | Right now referencing the constant `AbstractController::Rendering` causes `ActionView::Base` to be loaded, and thus the load hooks for action_view are run. If that load hook references any part of action view that then references action controller (such as `ActionView::TestCase`), the constant `AbstractController::Rendering` will attempt to be autoloaded and blow up. With this change, `ActionView::LoadPaths` no longer requires `ActionView::Base` (which it had no reason to require). There was a needed class from `AbstractController::Base` in the Rendering module, which I've moved into its own file so we don't need to load all of `AbstractController::Base` there. This commit fixes https://github.com/rails/rails-controller-testing/issues/21
* Add missing punctuation mark [ci skip]Gaurav Sharma2015-11-181-2/+2
|
* remove present? call; we do not need itAaron Patterson2015-11-021-1/+1
|
* Revert "ActionController::Base#process() now only takes an action name"Aaron Patterson2015-10-291-2/+2
| | | | This reverts commit 9f93a5efbba3e1cbf0bfa700a17ec8d1ef60d7c6.
* ActionController::Base#process() now only takes an action nameAaron Patterson2015-10-291-2/+2
| | | | | | rather than an action name and *args. The *args were not being used in regular applications outside tests. This causes a backwards compatibility issue, but reduces array allocations for most users.
* Remove not used requiresMarcin Olichwirowicz2015-09-011-1/+1
|
* Freeze string literals when not mutated.schneems2015-07-191-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | I wrote a utility that helps find areas where you could optimize your program using a frozen string instead of a string literal, it's called [let_it_go](https://github.com/schneems/let_it_go). After going through the output and adding `.freeze` I was able to eliminate the creation of 1,114 string objects on EVERY request to [codetriage](codetriage.com). How does this impact execution? To look at memory: ```ruby require 'get_process_mem' mem = GetProcessMem.new GC.start GC.disable 1_114.times { " " } before = mem.mb after = mem.mb GC.enable puts "Diff: #{after - before} mb" ``` Creating 1,114 string objects results in `Diff: 0.03125 mb` of RAM allocated on every request. Or 1mb every 32 requests. To look at raw speed: ```ruby require 'benchmark/ips' number_of_objects_reduced = 1_114 Benchmark.ips do |x| x.report("freeze") { number_of_objects_reduced.times { " ".freeze } } x.report("no-freeze") { number_of_objects_reduced.times { " " } } end ``` We get the results ``` Calculating ------------------------------------- freeze 1.428k i/100ms no-freeze 609.000 i/100ms ------------------------------------------------- freeze 14.363k (± 8.5%) i/s - 71.400k no-freeze 6.084k (± 8.1%) i/s - 30.450k ``` Now we can do some maths: ```ruby ips = 6_226k # iterations / 1 second call_time_before = 1.0 / ips # seconds per iteration ips = 15_254 # iterations / 1 second call_time_after = 1.0 / ips # seconds per iteration diff = call_time_before - call_time_after number_of_objects_reduced * diff * 100 # => 0.4530373333993266 miliseconds saved per request ``` So we're shaving off 1 second of execution time for every 220 requests. Is this going to be an insane speed boost to any Rails app: nope. Should we merge it: yep. p.s. If you know of a method call that doesn't modify a string input such as [String#gsub](https://github.com/schneems/let_it_go/blob/b0e2da69f0cca87ab581022baa43291cdf48638c/lib/let_it_go/core_ext/string.rb#L37) please [give me a pull request to the appropriate file](https://github.com/schneems/let_it_go/blob/b0e2da69f0cca87ab581022baa43291cdf48638c/lib/let_it_go/core_ext/string.rb#L37), or open an issue in LetItGo so we can track and freeze more strings. Keep those strings Frozen ![](https://www.dropbox.com/s/z4dj9fdsv213r4v/let-it-go.gif?dl=1)
* [ci skip] Don't use TrueClass, FalseClass in docsclaudiob2015-07-021-6/+0
| | | | | | | | | This sort of documentation style comes from 2009, probably due to the merging of merb (see https://github.com/rails/rails/commit/38b608ecab2441cd0c4e75bc08bdf57fcf85dd71#diff-017d9bc9b1d2bdae199b938d72c15488R120). Rails follows Ruby's convention to define which values are "truthy" or "falsey", so there is no need to specify that the returned value must strictly be a TrueClass or FalseClass. /cc @fxn
* Remove mistaken end from controller_path doc [ci skip]Mehmet Emin İNAÇ2015-06-221-1/+1
|
* Remove ActionController::HideActions (closes #18336)brainopia2015-01-061-14/+2
|
* remove unneeded check since /_one_time_conditions/ is removedAditya Kapoor2015-01-051-2/+1
|
* Fix a few typos [ci skip]Robin Dupret2015-01-031-2/+2
|
* Better docs for AbstractControllerclaudiob2014-12-221-8/+12
| | | | | | Fixes internal links, adds examples and set fixed-width fonts. [ci skip]
* Pass symbol as an argument instead of a blockErik Michaels-Ober2014-11-291-1/+1
|
* Deprecate `*_path` methods in mailers@schneems and @sgrif2014-07-301-0/+8
| | | | | | | | | | | Email does not support relative links since there is no implicit host. Therefore all links inside of emails must be fully qualified URLs. All path helpers are now deprecated. When removed, the error will give early indication to developers to use `*_url` methods instead. Currently if a developer uses a `*_path` helper, their tests and `mail_view` will not catch the mistake. The only way to see the error is by sending emails in production. Preventing sending out emails with non-working path's is the desired end goal of this PR. Currently path helpers are mixed-in to controllers (the ActionMailer::Base acts as a controller). All `*_url` and `*_path` helpers are made available through the same module. This PR separates this behavior into two modules so we can extend the `*_path` methods to add a Deprecation to them. Once deprecated we can use this same area to raise a NoMethodError and add an informative message directing the developer to use `*_url` instead. The module with warnings is only mixed in when a controller returns false from the newly added `supports_relative_path?`. Paired @sgrif & @schneems
* Relpace `=~ Regexp.new str` with `.include? str` in AC::Base#_valid_action_name?Viktar Basharymau2014-06-191-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Because it is more natural way to test substring inclusion. Also, in this particular case it is much faster. In general, using `Regexp.new str` for such kind of things is dangerous. The string must be escaped, unless you know what you're doing. Example: Regexp.new "\\" # HELLO WINDOWS # RegexpError: too short escape sequence: /\/ The right way to do this is escape the string Regexp.new Regexp.escape "\\" # => /\\/ Here is the benchmark showing how faster `include?` call is. ``` require 'benchmark/ips' Benchmark.ips do |x| x.report('include?') { !"index".to_s.include? File::SEPARATOR } x.report(' !~ ') { "index" !~ Regexp.new(File::SEPARATOR) } end __END__ Calculating ------------------------------------- include? 75754 i/100ms !~ 21089 i/100ms ------------------------------------------------- include? 3172882.3 (±4.5%) i/s - 15832586 in 5.000659s !~ 322918.8 (±8.6%) i/s - 1602764 in 4.999509s ``` Extra `.to_s` call is needed to handle the case when `action_name` is `nil`. If it is omitted, some tests fail.
* Remove duplicated to_s method call.Guo Xiang Tan2014-05-251-1/+1
|
* docs, make `ActionNotFound` public API. [ci skip]Yves Senn2014-05-111-1/+2
| | | | | | | | | This is a follow up to #15058. This exception is regularly raised during development. This means it will enter the user realm. We should provide an API page to show that this exception is public API. /cc @schneems
* adding complete message in documentation [ci skip]Gaurav Sharma2014-05-111-3/+4
|
* Only accept actions without File::SEPARATOR in the name.Rafael Mendonça França2014-05-061-3/+25
| | | | | | | | | This will avoid directory traversal in implicit render. Fixes: CVE-2014-0130 Conflicts: actionpack/lib/abstract_controller/base.rb
* Get rid of extra local var that does not add to the logicCarlos Antonio da Silva2014-05-051-2/+2
| | | | There are too many "action name" variables around the process method.
* Capitalize the first letter of sentenceTatsuro Baba2013-03-181-1/+1
|
* fix uninitialized ivar warningsAaron Patterson2012-10-251-0/+10
|
* remove 'then' from conditional statementNihad Abbasov2012-10-141-2/+4
|
* copy edit[ci skip]Vijay Dev2012-05-231-1/+1
|
* Update documentation for AbstractController::BaseHenrik Hodne2012-05-201-3/+11
|
* avoid empty api pagesVijay Dev2012-04-081-2/+5
|
* AbstractController.action_methods should return a SetSantiago Pastorino2012-03-101-2/+3
|
* Fix AbstractController#controller_path docAlexey Vakhov2012-02-191-1/+1
|
* Fix AbstractController::Base#hidden_actions commentAlexey Vakhov2012-02-181-2/+2
|
* Remove extra white spaces on ActionPack docs.Sebastian Martinez2011-05-231-1/+1
|
* better styling on #available_action? docsSebastian Martinez2011-05-061-2/+2
|