Last Update: 2012-06-15 14:24:40 -0700

Class methods shared by all models

Many class methods can be overridden for particular use cases by setting other methods or instance variables. For example, scaffold_fields is a method that takes an action, such as :new. scaffold_fields(:new) will first check if scaffold_new_fields is a method, and will call it if so. If not, it will check if @scaffold_new_fields is defined, and use it if so. If not, will take the default course of action.

The first argument to the overridable method is used to search for the override method or instance variable. If a override method is used, the remaining arguments to the overridable method will be passed to it. Otherwise, the default method will be used.

For example, scaffold_find_object(action, id, options) is an overridable method. That means if :delete is the action, it will first look for scaffold_delete_find_object, and if it exists it will call scaffold_delete_find_object(id, options).

If a method can be overridden by an instance variable, it should have only one argument.

The methods that are overridable by other methods are (without the “scaffold_” prefix): add_associated_objects, associated_objects, association_find_object, association_find_objects, find_object, find_objects, new_associated_object_values, remove_associated_objects, save, unassociated_objects, and filter_attributes.

The methods that are overridable by other methods or instance variables are (again, without the “scaffold_” prefix): associated_human_name, association_use_auto_complete, fields, include, select_order, attributes, include_association, and select_order_association.

Most methods that find objects check options[scaffold_session_value] as a security check if scaffold_session_value is set.

There are some methods that are so similar that they are dynamically defined using define_method. They are:

  • scaffold_association_list_class: The html class attribute of the association list

  • scaffold_habtm_with_ajax: Whether to use Ajax when scaffolding habtm associations for this model

  • scaffold_load_associations_with_ajax: Whether to use Ajax when loading associations on the edit page

  • scaffold_browse_records_per_page: The number of records to show on each page when using the browse scaffold

  • scaffold_convert_text_to_string: Whether to use input of type text instead of a text area for columns of type :text

  • scaffold_search_results_limit: The maximum number of results to show on the scaffolded search results page

Each of these methods can be set with an instance variable. If the instance variable is not set, it will use the default value from SCAFFOLD_OPTIONS.