On 9-jun-2006, at 23:12, Silvela, Jaime (Exchange) wrote:
> Hi, I don?t know if this has been suggested before (btw is there a
> searchable history of the mailing list? ? I?m new)
>
>
>
> My problem is the following. I have a form with many input fields,
> sorted out and cleanly formatted using tables.
>
> I would need to offer users a page exactly like it, only not
> editable. And in particular, text areas in the ?edit? page will
> develop scrollbars and truncate the text if it?s too long, but in
> the ?view? page, I?d like to show everything.
>
>
>
> Of course, the ideal solution would be to use a parameter into the
> page (or partial or component) to switch editability on or off. For
> that, form helpers should take an ?editable? parameter, and
> produce an input field or just a value if the parameter is false.
>
Make an abstraction on top of the field helpers that will handle this
for you and handle the requirements.
You can look at the way of batch-creation of "covering" helper
methods in my plugin here:
http://julik.textdriven.com/svn/tools/rails_plugins/simplified_form/
lib/simplified_form.rb
Of particular interest:
field_helper_methods =
ActionView::Helpers::FormHelper.instance_methods.reject{|m| not
m.to_s =~ /field$/ }
field_helper_methods.concat
ActionView::Helpers::DateHelper.instance_methods.reject{|m| not
m.to_s =~ /select/}
field_helper_methods.concat
[:radio_button, :text_area, :check_box, :file_column_field ]
method_code = ""
collection_methods =
ActionView::Helpers::FormOptionsHelper.instance_methods.reject do |m|
(m.to_s =~ /for_select$/) or (not m.to_s =~ /select$/)
end
You then build a helper module on the fly and include it into your
controller. Judging from what you need you only have to replace the
actual field helpers with some generic display routine that will
detect the proper representation of the data based on the helper used.
--
Julian ''Julik'' Tarkhanov
please send all personal mail to
me at julik.nl