Module: InheritedResources::SingletonHelpers
- Defined in:
- lib/inherited_resources/singleton_helpers.rb
Overview
singleton
Singletons are usually used in associations which are related through has_one and belongs_to. You declare those associations like this:
class ManagersController < InheritedResources::Base
belongs_to :project, :singleton => true
end
But in some cases, like an AccountsController, you have a singleton object that is not necessarily associated with another:
class AccountsController < InheritedResources::Base
defaults :singleton => true
end
Besides that, you should overwrite the methods :resource and :build_resource to make it work properly:
class AccountsController < InheritedResources::Base
defaults :singleton => true
protected
def resource
@current_user.account
end
def build_resource(attributes = {})
Account.new(attributes)
end
end
When you have a singleton controller, the action index is removed.