- 1.0.0 (0)
- 1.1.6 (0)
- 1.2.6 (-38)
- 2.0.3
- 2.1.0
- 2.2.1
- 2.3.8
- 3.0.0
- 3.0.9
- 3.1.0
- 3.2.1
- 3.2.8
- 3.2.13
- 4.0.2
- 4.1.8
- 4.2.1
- 4.2.7
- 4.2.9
- 5.0.0.1
- 5.1.7
- 5.2.3
- 6.0.0
- 6.1.3.1
- 6.1.7.7
- 7.0.0
- 7.1.3.2
- 7.1.3.4
- What's this?
Dependencies control what classes are needed for the controller to run its course. This is an alternative to doing explicit require statements that bring a number of benefits. It’s more succinct, communicates what type of dependency we’re talking about, can trigger special behavior (as in the case of observer), and enables Rails to be clever about reloading in cached environments like FCGI. Example:
class ApplicationController < ActionController::Base model :account, :company, :person, :project, :category helper :access_control service :notifications, :billings observer :project_change_observer end
Please note that a controller like ApplicationController will automatically attempt to require_dependency on a model of its singuralized name and a helper of its name. If nothing is found, no error is raised. This is especially useful for concrete controllers like PostController:
class PostController < ApplicationController # model :post (already required) # helper :post (already required) end
Also note, that if the models follow the pattern of just 1 class per file in the form of MyClass => my_class.rb, then these classes don’t have to be required as Active Support will auto-require them.