Module InheritedResources::ClassMethods
In: lib/inherited_resources/class_methods.rb

Methods

Included Modules

BelongsToHelpers SingletonHelpers PolymorphicHelpers BelongsToHelpers ShallowHelpers

Protected Instance methods

Defines wich actions will be inherited from the inherited controller. Syntax is borrowed from resource_controller.

  actions :index, :show, :edit
  actions :all, :except => :index

Defines that this controller belongs to another resource.

  belongs_to :projects

Options

  • :parent_class - Allows you to specify what is the parent class.
      belongs_to :project, :parent_class => AdminProject
    
  • :class_name - Also allows you to specify the parent class, but you should
                           give a string. Added for ActiveRecord belongs to compatibility.
    
  • :instance_name - The instance variable name. By default is the name of the association.
      belongs_to :project, :instance_name => :my_project
    
  • :finder - Specifies which method should be called to instantiate the parent.
      belongs_to :project, :finder => :find_by_title!
    

    This will make your projects be instantiated as:

      Project.find_by_title!(params[:project_id])
    

    Instead of:

      Project.find(params[:project_id])
    
  • :param - Allows you to specify params key to retrieve the id.
                      Default is :association_id, which in this case is :project_id.
    
  • :route_name - Allows you to specify what is the route name in your url
                           helper. By default is association name.
    
  • :collection_name - Tell how to retrieve the next collection. Let‘s
                                suppose you have Tasks which belongs to Projects
                                which belongs to companies. This will do somewhere
                                down the road:
    
       @company.projects
    

    But if you want to retrieve instead:

       @company.admin_projects
    

    You supply the collection name.

  • :polymorphic - Tell the association is polymorphic.
  • :singleton - Tell it‘s a singleton association.
  • :optional - Tell the association is optional (it‘s a special
                         type of polymorphic association)
    

Defines custom restful actions by resource or collection basis.

  custom_actions :resource => [:delete, :transit], :collection => :search

Options

  • :resource - Allows you to specify resource actions.
      custom_actions :resource => :delete
                          This macro creates 'delete' method in controller and defines
                          delete_resource_{path,url} helpers. The body of generated 'delete'
                          method is same as 'show' method. So you can override it if need
    
  • :collection - Allows you to specify collection actions.
      custom_actions :collection => :search
                          This macro creates 'search' method in controller and defines
                          search_resources_{path,url} helpers. The body of generated 'search'
                          method is same as 'index' method. So you can override it if need
    

Used to overwrite the default assumptions InheritedResources do. Whenever this method is called, it should be on the top of your controller, since almost other methods depends on the values given to <>defaults.

Options

  • :resource_class - The resource class which by default is guessed
                               by the controller name. Defaults to Project in
                               ProjectsController.
    
  • :collection_name - The name of the collection instance variable which
                                is set on the index action. Defaults to :projects in
                                ProjectsController.
    
  • :instance_name - The name of the singular instance variable which
                              is set on all actions besides index action. Defaults to
                              :project in ProjectsController.
    
  • :route_collection_name - The name of the collection route. Defaults to :collection_name.
  • :route_instance_name - The name of the singular route. Defaults to :instance_name.
  • :route_prefix - The route prefix which is automically set in namespaced
                             controllers. Default to :admin on Admin::ProjectsController.
    
  • :singleton - Tells if this controller is singleton or not.
  • :finder - Specifies which method should be called to instantiate the resource.
      defaults :finder => :find_by_slug
    
nested_belongs_to(*symbols, &block)

Alias for belongs_to

A quick method to declare optional belongs to.

A quick method to declare polymorphic belongs to.

A quick method to declare singleton belongs to.

Defines the role to use when creating or updating resource. Makes sense when using rails 3.1 mass assignment conventions

[Validate]