Skip to content
cainlevy edited this page Sep 14, 2010 · 22 revisions

If you want to customize the form interface for a column, you have two choices. You can define a specially named partial, or you can define a specially named method in your helper file. The difference between the partial and the helper method is that the partial will be responsible for displaying the label and everything, whereas the helper will only be responsible for displaying the input element (or other interface).

These overrides can be used to hide fields on the form, or even to replace standard inputs with javascript-enabled inputs.

These overrides are currently used by Create and Update.

Helper Override

The helper override is only responsible for display the input element (or whatever else you want). It should be named #{column_name}_form_column. If you want the post to be handled by ActiveScaffold, you need to use the params[:record] namespace. With the helper override this is taken care of if you use the second argument: the input name. See the example below for more details.

Note that with even with subforms, helper overrides only apply to the current controller.

Warning: We were able to patch date_select, time_select, and datetime_select to support a :name parameter. With the other set of methods (select_date, select_time, select_datetime) you must use the :prefix parameter instead. See the example below.

Example:
module UserHelper

  1. display the “is_admin” field as a checkbox instead of a dropdown
    def is_admin_form_column(record, input_name)
    check_box :record, :is_admin, :name => input_name
    end
def date_received_form_column(record, input_name)
  1. with date_select we can use :name
    date_select :record, :date_received, :name => input_name
  2. but if we used select_date we would have to use :prefix
    #select_date record[:date_received], :prefix => input_name
    end
    end

Partial Override (overriding the form element and the label)

The partial override is responsible for displaying the field label, element, description, etc.. It should be named _#{column_name}_form_column.rhtml and be placed in your controller’s views folder.

Example:

  1. in app/views/roles/_description_form_column.rhtml
Description <%= text_area :record, :description, :cols => 25, :rows => 10 %>
  1. this works too:
Description <%= text_area_tag(‘record[description]’, @record.description, :size => ‘25×10’)

Sometimes you may wish to access the active scaffold configuration in your partial override. By default, the variable ApiColumn). The column variable has 3 important attributes: column.name, column.label, and column.description. You can access other configuration columns by using active_scaffold_config.columns [:column_name].

  1. in app/views/roles/city_form_column.rhtml
    <% scope ||= nil >


    = “record_#{column.name}” >">
    <
    = column.label >,
    <
    = active_scaffold_config.columns[:state].label >
    <
    = active_scaffold_config.columns[:zip].label >



    <
    = form_column column, scope >,
    <
    = form_column(active_scaffold_config.columns[:state], scope) >
    <
    = form_column(active_scaffold
    config.columns[:zip], scope) %>

Clone this wiki locally