aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/lib/abstract_controller
Commit message (Collapse)AuthorAgeFilesLines
...
* Merge branch 'master' of github.com:rails/docrailsVijay Dev2015-11-151-5/+5
|\
| * adding missing `.` Gaurav Sharma2015-11-151-5/+5
| |
* | 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.
* specify deprecated waring, follow the standard conventionsGaurav Sharma2015-10-281-1/+1
| | | | `skip_filter`, `skip_action_callback` may both are deprecated in Rails 5.1 so waring msg should be specific.
* Use `Mime[:foo]` instead of `Mime::Type[:FOO]` for back compatJeremy Daer2015-10-062-10/+5
| | | | | | | | | | | | | | | | | Rails 4.x and earlier didn't support `Mime::Type[:FOO]`, so libraries that support multiple Rails versions would've had to feature-detect whether to use `Mime::Type[:FOO]` or `Mime::FOO`. `Mime[:foo]` has been around for ages to look up registered MIME types by symbol / extension, though, so libraries and plugins can safely switch to that without breaking backward- or forward-compatibility. Note: `Mime::ALL` isn't a real MIME type and isn't registered for lookup by type or extension, so it's not available as `Mime[:all]`. We use it internally as a wildcard for `respond_to` negotiation. If you use this internal constant, continue to reference it with `Mime::ALL`. Ref. efc6dd550ee49e7e443f9d72785caa0f240def53
* move file sending to the response objectAaron Patterson2015-10-051-2/+2
| | | | | | | Just a slight refactor that delegates file sending to the response object. This gives us the advantage that if a webserver (in the future) provides a response object that knows how to do accelerated file serving, it can implement this method.
* stop calling deprecated methodsAaron Patterson2015-09-212-4/+4
| | | | | We should be asking the mime type method for the mime objects rather than via const lookup
* push content_type assigment in to metalAaron Patterson2015-09-081-4/+4
| | | | | everything above metal really doesn't care about setting the content type, so lets rearrange these methods to be in metal.
* avoid useless string allocationsAaron Patterson2015-09-081-1/+0
| | | | | | | _set_content_type only does something when there is a request object, otherwise the return value of _get_content_type is always ignored. This commit moves everything to the module that has access to the request object so we'll never to_s unless there is a reason
* Remove not used requiresMarcin Olichwirowicz2015-09-011-1/+1
|
* Set the content-type to `text/html` if the options[:html] is trueakihiro172015-08-291-2/+2
| | | | | | In this commit, we set the content-type to `text/html` in AbstractController if the `options[:html]` is true so that we don't include ActionView::Rendering into ActionController::Metal to set it properly. I removed the if `options[:plain]` statement because `AbstractController#rendered_format` returns `Mime::TEXT` by default.
* Remove useless conditionalAaron Patterson2015-08-261-1/+1
| | | | | If the response method is defined, then calling `response` will return a response.
* remove useless codeAaron Patterson2015-08-261-1/+0
| | | | | | | | | | If AV::Rendering is mixed in, then `rendered_format` will be calculated based on the current `lookup_context`, but calling `_process_format` will set the `rendered_format` back on to the same lookup context where we got the information in the first place! Instead of getting information from an object, then setting the same information back on to that object, lets just do nothing instead!
* only call self.content_type= when there is a responseAaron Patterson2015-08-261-1/+12
| | | | | Apparently the AbstractController (whatever "abstract" means) is expected to work without a request and response.
* Pull `plain` content type handling up to `render`Aaron Patterson2015-08-261-2/+3
| | | | | `render` is the only possible source for the `plain` option. Pulling the conditional up to the `render` method removes far away conditionals
* stop passing the options hash to `_process_format`Aaron Patterson2015-08-261-2/+2
| | | | | | We don't need to pass the full hash just to pull one value out. It's better to just pass the value that the method needs to know about so that we can abstract it away from "options"
* Initialize symbols instead of mapping to_sym on the set of stringsMarcin Olichwirowicz2015-08-151-2/+2
|
* Freeze string literals when not mutated.schneems2015-07-192-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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
|
* Raise ArgumentError if an unrecognised callback is skippedIain Beeston2015-04-031-3/+3
| | | | | | | | | | | | | | At present, if you skip a callback that hasn't been defined, activesupport callbacks silently does nothing. However, it's easy to mistype the name of a callback and mistakenly think that it's being skipped, when it is not. This problem even exists in the current test suite. CallbacksTest::SkipCallbacksTest#test_skip_person attempts to skip callbacks that were never set up. This PR changes `skip_callback` to raise an `ArgumentError` if the specified callback cannot be found.
* Removed non-standard and unused require 'active_support/deprecation' from ↵Vipul A M2015-02-271-2/+0
| | | | parts out of active_support.
* fix NameError in `skip_filter`. callback doesn't exist.yuuji.yaginuma2015-02-271-1/+1
|
* Deprecate `AbstractController::Callbacks#skip_action_callback`Iain Beeston2015-02-241-0/+1
| | | | | | | | | | As part of #19029, in future `skip_before_action`, `skip_after_action` and `skip_around_action` will raise an ArgumentError if the specified callback does not exist. `skip_action_callback` calls all three of these methods and will almost certainly result in an ArgumentError. If anyone wants to remove all three callbacks then they can still call the three individual methods. Therefore let's deprecate `skip_action_callback` now and remove it when #19029 is merged.
* Merge pull request #11790 from printercu/patch-3Rafael Mendonça França2015-02-121-7/+8
|\ | | | | | | ActionController#translate supports symbols
| * ActionController#translate also lookups shortcut without action nameMax Melentiev2013-10-221-1/+5
| |
| * ActionController#translate supports symbolsprintercu2013-09-251-6/+3
| | | | | | | | Made it similar to views helper.
* | Use public Module#include, in favor of https://bugs.ruby-lang.org/issues/8846robertomiranda2015-01-311-2/+2
| | | | | | | | ref: https://github.com/rails/rails/pull/18763#issuecomment-72349769
* | fix typo in `_filter` deprecation message. [ci skip]Yves Senn2015-01-301-5/+5
| |
* | Deprecate all *_filter callbacks in favor of *_action callbacksAbdelkader Boudih2015-01-081-5/+27
| |
* | Merge pull request #18404 from claudiob/rebase-14549Rafael Mendonça França2015-01-081-0/+10
|\ \ | | | | | | Add test case and documentation for skip_before_filter.
| * | Add test/doc for :if/:except in skip_before_actionclaudiob2015-01-081-0/+5
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The new test/docs further explain the conflicts that can happen when mixing `:if`/`:unless` options with `:only`/`:except` options in `skip_before_action`. The gist is that "positive" filters always have priority over negative ones. The previous commit already showed that `:only` has priority over `:if`. This commit shows that `:if` has priority over `:except`. For instance, the following snippets are equivalent: ```ruby skip_before_action :some_callback, if: -> { condition }, except: action ``` ```ruby skip_before_action :some_callback, if: -> { condition } ```
| * | Add test case and documentation for skip_before_filter.Lauro Caetano2015-01-081-0/+5
| | | | | | | | | | | | | | | | | | | | | | | | Test case for using skip_before_filter with the options :only and :if both present. In this case, the :if option will be ignored and :only will be executed. Closes #14549 (the commit was cherry-picked from there).
* | | Remove ActionController::HideActions (closes #18336)brainopia2015-01-061-14/+2
|/ /
* | remove unneeded check since /_one_time_conditions/ is removedAditya Kapoor2015-01-051-2/+1
| |
* | Merge pull request #17227 from claudiob/explicitly-abort-callbacksRafael Mendonça França2015-01-031-1/+1
|\ \ | | | | | | | | | | | | | | | | | | Introduce explicit way of halting callback chains by throwing :abort. Deprecate current implicit behavior of halting callback chains by returning `false` in apps ported to Rails 5.0. Completely remove that behavior in brand new Rails 5.0 apps. Conflicts: railties/CHANGELOG.md
| * | Throw :abort halts default CallbackChainsclaudiob2015-01-021-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This commit changes arguments and default value of CallbackChain's :terminator option. After this commit, Chains of callbacks defined **without** an explicit `:terminator` option will be halted as soon as a `before_` callback throws `:abort`. Chains of callbacks defined **with** a `:terminator` option will maintain their existing behavior of halting as soon as a `before_` callback matches the terminator's expectation. For instance, ActiveModel's callbacks will still halt the chain when a `before_` callback returns `false`.
* | | Fix a few typos [ci skip]Robin Dupret2015-01-032-3/+3
| | |
* | | Merge branch 'master' of github.com:rails/docrailsVijay Dev2015-01-033-18/+24
|\ \ \ | |/ / |/| |
| * | Better docs for AbstractControllerclaudiob2014-12-223-18/+24
| | | | | | | | | | | | | | | | | | Fixes internal links, adds examples and set fixed-width fonts. [ci skip]
* | | Merge pull request #8740 from amatsuda/missing_source_fileRafael Mendonça França2015-01-021-1/+1
|\ \ \ | |/ / |/| | | | | | | | | | | | | | replace use of MissingSourceFile with LoadError Conflicts: activesupport/test/core_ext/load_error_test.rb
| * | replace use of MissingSourceFile with LoadErrorAkira Matsuda2013-01-041-1/+1
| | |
* | | Pass symbol as an argument instead of a blockErik Michaels-Ober2014-11-291-1/+1
| | |
* | | give a better error message for misspelled helpersXavier Noria2014-10-251-1/+11
| | | | | | | | | | | | | | | | | | See comment in this patch for the rationale. References #16468
* | | remove deprecated `MissingHelperError` proxy.Yves Senn2014-08-141-3/+0
| | | | | | | | | | | | The error was moved outside of the `ClassMethods` module.
* | | Deprecate `*_path` methods in mailers@schneems and @sgrif2014-07-302-3/+11
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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.
* | | Partially revert deprecation of *_filterRafael Mendonça França2014-06-031-27/+6
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | We are going to deprecate only on Rails 5 to make easier plugin maintainers support different Rails versions. Right now we are only discouraging their usage. This reverts commit 6c5f43bab8206747a8591435b2aa0ff7051ad3de. Conflicts: actionpack/CHANGELOG.md