The Artima Developer Community
Sponsored Link

Ruby Buzz Forum
Scaffolding XML columns as text area boxes

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Leon Katsnelson

Posts: 105
Nickname: db2onrails
Registered: Jun, 2006

Leon Katsnelson is a Program Director at the IBM Toronto Lab working on spreading the joy of DB2.
Scaffolding XML columns as text area boxes Posted: Jan 6, 2007 2:48 AM
Reply to this message Reply

This post originated from an RSS feed registered with Ruby Buzz by Leon Katsnelson.
Original Post: Scaffolding XML columns as text area boxes
Feed Title: DB2 on Rails
Feed URL: http://feeds.feedburner.com/DB2OnRails
Feed Description: Agile development for enterprises large and small
Latest Ruby Buzz Posts
Latest Ruby Buzz Posts by Leon Katsnelson
Latest Posts From DB2 on Rails

Advertisement

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.

Read: Scaffolding XML columns as text area boxes

Topic: (Poignant) Guide Earlies Previous Topic   Next Topic Topic: 2006 in Review

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use