Sunday, October 7, 2007

Active Scaffold : Roll your own form_ui ?

In the trunk version or the soon-to-be released 1.1 release, we can configure columns, on a per controller basis, such as :select, :calendar, :textarea and :checkbox but what about :text_input ?

Previously, to control the width of a given text-input column, I had to put in the helper something like this either in application.rb or controller_helper.rb

def faq_form_column(record, input_name)
text_field_tag('record[faq]', @record.faq, { :autocomplete => "off", :size => 60, :class => 'text-input'})
end


Now, I can do this :-

config.columns[:biz_name].options = { :autocomplete => "off", :size => 30, :class => 'text-input'}

config.columns[:biz_name].form_ui = :tex-input


How is this done ? Simple, just add this method once in applcation_helper.rb

def active_scaffold_input_tex-input(column, options)
text_field :record, column.name, options
end

Yes, you can roll your own form.ui :-)

2 comments:

Unknown said...

Hi CCH,

I tried your code above to control the length of a text input field but I do not seem to be coming right.

I had to firstly modify the application helper as text-input is not picked up.


def active_scaffold_input_text_input(column, options)
text_field :record, column.name, options
end


Also in the controller I had to modify :text-input to :text_input otherwise it throws an error.

config.columns[:firstname].options = { :autocomplete => "off", :size => 10, :class => 'text-input'}
config.columns[:firstname].form_ui = :text_input

Maybe I don't see the big picture.
Anyway if you can help me I will really really appreciate it.

Regards
Uncle Mike

Unknown said...

Hi, any updates on this sample? Have the same problems as Uncle Mike and seems this article is the single one describing how to customize active scaffold in this way.

Welcome to Rails.. Rails... Rails !

In 1995, I started the popular Clipper...Clipper... Clipper website (no blogs then) which was very popular and linked by virtually every Clipper-related site. When I switched to Windows via Delphi in 1997, I started the Delphi... Delphi... Delphi site. In June 2007, I discovered Ruby on Rails and no prize for guessing what I am gonna name this blog. which I started on 2nd October 2007.

As at 10th June 2010, we have 13,364 unique visitors from more than 84 countries such as Angola, Andorra, Argentina, Australia, Austria, Algeria,Barbados, Bosnia and Herzogovina, Belgium, Brazil, Bulgaria, Bangladesh, Belarus, Bolivia, Chile, Cambodia, Cape Vede, Canada, China, Colombia, Costa Rica, Croatia, Cyprus, Czech Republic, Denmark, Egypt, Estonia, Finland, France, Guadeloupe, Guatemala, Germany, Greece, Hong Kong, Hungary, India, Indonesia, Ireland, Israel, Italy, Japan, Kenya, Korea, Lithuania, Latvia, Malaysia, Mexico, Macao, Netherlands, Nepal, Norway, New Zealand, Oman, Panama, Peru, Poland, Portugal,Paraguay , Philippines, Romania, Russian Federation, Saudi Arabia, Singapore, Spain, Slovakia, Slovenia, Serbia, South Korea, Slovenia, South Africa, Spain, Switzerland, Sri Lanka, Sweden, Taiwan, Thailand, Turkey, United Arab Emirates, Ukraine, USA, UK, Venezuela, Vietnam

CCH
10th June 2010, 19:42