Scaffolding XML columns as text area boxes
The Rails adapter and the Ruby driver for IBM DB2 enable you to take full advantage of the exclusive pureXML capabilities. XML fields are properly handled and also recognized when using migrations. We do not bind the content of XML columns to a specific XML Ruby representation (e.g. REXML) but rather let the user decide what they’d prefer to use, in light also of the fact that mapping to a simple string is often all that is required given the fast XQuery/XPath querying features provided out of the box by DB2.
The scaffolding generator ignores XML fields though. This is due to the fact that the bult-in scaffolding generates form elements for only a few datatypes. For example :time and :binary are excluded, and foreign keys are not handled as well. Users will typically want to handle XML fields in a customized way, for instance, showing only certain elements of the XML document in their forms. However if you wish to enable by default the automatic generation of text area boxes when using scaffolding, you can edit C:\ruby\lib\ruby\gems\1.8\gems\actionpack-1.12.5\lib\action_view\helpers\active _record_helper.rb (or the equivalent on your system) by replacing the to_tag method with the following:
def to_tag(options = {})
case column_type
when :string
field_type = @method_name.include?(”password”) ? “password” : “text”
to_input_field_tag(field_type, options)
when :text, :xml
to_text_area_tag(options)
when :integer, :float
to_input_field_tag(”text”, options)
when :date
to_date_select_tag(options)
when :datetime, :timestamp
to_datetime_select_tag(options)
when :boolean
to_boolean_select_tag(options)
end
end
As you can see, all we are doing here is adding the XML datatype to the list of cases which require the rendering of a text area box.
January 06 2007 | How-to and Tips&Tricks | 1 Comment »
on Rails