aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/lib/action_controller/metal/helpers.rb
Commit message (Collapse)AuthorAgeFilesLines
* Use string lengths instead of regexp to extract pathMatthew Draper2018-08-231-2/+1
| | | | | | | | | | The regexp was introduced in 186ac4cdaa911a9af659a29f2179a19b99dea13b, and looks cosmetic. While they should be functionally identical in theory, in practice, case insensitive (but preserving) filesystems can give results that are differently-cased from the pattern we supplied. I don't know how to force the filesystem to do the surprising thing, even when running in an environment that _could_, so no new test.
* Use frozen string literal in actionpack/Kir Shatrov2017-07-291-0/+2
|
* Revert "Merge pull request #29540 from kirs/rubocop-frozen-string"Matthew Draper2017-07-021-1/+0
| | | | | This reverts commit 3420a14590c0e6915d8b6c242887f74adb4120f9, reversing changes made to afb66a5a598ce4ac74ad84b125a5abf046dcf5aa.
* Enforce frozen string in RubocopKir Shatrov2017-07-011-0/+1
|
* Add option for class_attribute default (#29270)David Heinemeier Hansson2017-05-291-3/+2
| | | | | | | | | | | | * 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
* Fix broken comments indentation caused by rubocop auto-correct [ci skip]Ryuta Kamizono2016-09-141-1/+1
| | | | | | 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.
* normalizes indentation and whitespace across the projectXavier Noria2016-08-061-3/+3
|
* Helpers doc grammar fix [skip ci]Jon Atack2016-05-071-2/+2
|
* Implement helpers proxy in controller instance levelRafael Mendonça França2016-05-051-1/+6
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | It is a common pattern in the Rails community that when people want to :xa use any kind of helper that is defined inside app/helpers they includes the helper module inside the controller like: module UserHelper def my_user_helper # ... end end class UsersController < ApplicationController include UserHelper def index render inline: my_user_helper end end This has problem because the helper can't access anything that is defined in the view level context class. Also all public methods of the helper become available in the controller what can lead to undesirable methods being routed and behaving as actions. Also if you helper depends on other helpers or even Action View helpers you need to include each one of these dependencies in your controller otherwise your helper is not going to work. We already have a helpers proxy at controller class level but that proxy doesn't have access to the instance variables defined in the controller. With this new instance level helper proxy users can reuse helpers in the controller without having to include the modules and with access to instance variables defined in the controller. class UsersController < ApplicationController def index render inline: helpers.my_user_helper end end
* typo "description not clear corrected with proper description and ↵kishore-mohan2015-09-021-2/+2
| | | | action_controller_overview file Rails' -> Rails" [ci skip]
* Freeze string literals when not mutated.schneems2015-07-191-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)
* Spelling/typo/grammatical fixes [ci skip]karanarora2015-05-231-1/+1
| | | | | | | | | | spelling fix [ci skip] example to be consistent [ci skip] grammatical fix typo fixes [ci skip]
* Tiny documentation edits [ci skip]Robin Dupret2015-03-031-1/+1
|
* [ci skip] Add documentation for Helpers#all_helpers_from_pathAnton Davydov2015-03-031-0/+4
|
* pass app config to controller helper proxyTima Maslyuchenko2013-10-241-1/+5
| | | | | | | | | | | | | | | After this fix application config become available when calling helper outisde of view config/application.rb #... config.asset_host = 'http://mycdn.com' #... Somewhere else ActionController::Base.helpers.asset_path('fallback.png') # => http://mycdn.com/assets/fallback.png
* Improve documentation for controller how to get included helpers [ci skip]Paul Nikitochkin2013-07-301-1/+1
| | | | Closes #11671
* Remove unecessary variable call, `#sort!` always returns an arrayAgis Anastasopoulos2013-04-071-1/+0
|
* Bring back helpers_path attr accessorCarlos Antonio da Silva2012-12-131-1/+1
| | | | | This is apparently used by the railtie to setup the app helpers paths correctly between initializers. I'll need to check it further.
* Refactor helpers code in Action Pack a bitCarlos Antonio da Silva2012-12-131-5/+4
| | | | | | | | * Avoid calling class_eval when not needed * Remove helpers_path attr accessor, it's defined as a class attribute a few lines later * Avoid creating extra arrays when finding helpers, use flat_map and sort! * Remove not required refer variable when redirecting :back
* load active_support/core_ext/class/attribute in active_support/railsXavier Noria2012-08-021-1/+0
|
* Fix sorting of helpers from different pathsPiotr Sarnacki2012-05-281-2/+2
| | | | | | | | | | | | | | | | When more than one directory for helpers is provided to a controller, it should preserver the order of directories. Given 2 paths: MyController.helpers_paths = ["dir1/helpers", "dir2/helpers"] helpers from dir1 should be loaded first. Before this commit, all helpers were mixed and then sorted alphabetically, which essentially would require to rename helpers to get desired order. This is a problem especially for engines, where you would like to be able to predict accurately which engine helpers will load first. (closes #6496)
* Removing ==Examples and last blank lines of docs from actionpackFrancesco Rodriguez2012-05-151-1/+0
|
* Simplify helpers handling. Ensure Metal can run AC hooks.José Valim2012-03-151-0/+1
|
* Use Kernel#Array in ActionController::HelpersRafael Mendonça França2012-01-051-2/+1
|
* Remove unecessary config_accessors.José Valim2011-12-241-1/+1
|
* fix helpers behavior descriptionAlexey Vakhov2011-09-031-3/+6
|
* find(:all) => allAkira Matsuda2011-07-081-1/+1
|
* Make ActionController::Base.modules_for_helpers and ↵Piotr Sarnacki2011-04-251-26/+26
| | | | ActionController::Base.all_helpers_from_path public methods
* Add config.action_controller.include_all_helpers, by default it is set to true.Piotr Sarnacki2010-11-181-1/+2
| | | | | | | In older rails versions there was a way to use only helpers from helper file corresponding to current controller and you could also include all helpers by saying 'helper :all' in controller. This config allows to return to older behavior by setting it to false.
* Remove more warnings shadowing outer local variable.Emilio Tagua2010-09-271-3/+3
| | | | Signed-off-by: Santiago Pastorino <santiago@wyeworks.com>
* Remove more warnings shadowing outer local variable.Emilio Tagua2010-09-271-3/+3
|
* Cleanup deprecation warnings in Action ControllerCarlos Antonio da Silva2010-09-061-11/+1
| | | | Signed-off-by: José Valim <jose.valim@gmail.com>
* Include application's helpers and router helpers by default, but include ↵Piotr Sarnacki2010-09-031-1/+5
| | | | engine's ones for controllers inside isolated namespace
* cleanup of ActionController::Metal inline documentationJoost Baaij2010-08-261-13/+11
|
* Fix setting helpers_path to a string or pathnameJeremy Kemper2010-07-071-2/+3
|
* Use caller for helpers_dir deprecation warningsJeremy Kemper2010-06-281-2/+2
|
* Ruby 1.9: helper path may be a pathname, so convert to a string before ↵Jeremy Kemper2010-05-161-1/+1
| | | | quoting for regexp
* Clean up the config object in ActionPack. Create config_accessor which just ↵José Valim2010-04-221-2/+2
| | | | delegates to the config object, reducing the number of deprecations and add specific tests.
* revises some <%= in rdocXavier Noria2010-04-051-1/+1
|
* Update AP to start locking down a public API. This work is parallel to some ↵Yehuda Katz2010-02-161-2/+2
| | | | docs I'm working on.
* Convert to class_attributeJeremy Kemper2010-02-011-1/+3
|
* Bring helpers_dir deprecation back.José Valim2010-01-301-0/+2
|
* Fix some backward incompatible behavior on AM.José Valim2010-01-301-15/+0
|
* AC railtie should configure helpers path.José Valim2010-01-261-3/+2
|
* Keep ActionController::Base.helpers_dir around for a bit longerJoshua Peek2010-01-261-37/+33
|
* Add a deprecation for helpers_dir.José Valim2010-01-251-0/+12
|
* Fix failing tests after merge.José Valim2010-01-241-0/+1
|
* Ensure helpers work from configured path.José Valim2010-01-241-8/+10
|
* Get rid of initializers global and create i18n railtie.José Valim2010-01-231-0/+2
|
* Stop overriding LoadError.new to return a MissingSourceError (and sometimes ↵Yehuda Katz2010-01-191-1/+1
| | | | nil!)