4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
|
# File 'lib/ul_form_builder/form_helpers.rb', line 4
def ul_form_for( record_or_name_or_array, *args, &proc )
raise ArgumentError, "Missing block" unless block_given?
options = args.
options.merge!( :builder => ActionView::Base::GUnorderedListFormBuilder )
case record_or_name_or_array
when String, Symbol
object_name = record_or_name_or_array
when Array
object = record_or_name_or_array.last
object_name = ActionController::RecordIdentifier.singular_class_name( object )
apply_form_for_options!( record_or_name_or_array, options )
args.unshift object
else
object = record_or_name_or_array
object_name = ActionController::RecordIdentifier.singular_class_name( object )
apply_form_for_options!( [object], options )
args.unshift object
end
html_options = options.delete( :html ) || {}
html_options.merge!( :class => options.delete( :class ) )
concat( form_tag( options.delete( :url ) || {}, html_options || {} ) )
concat( "<ul>" )
fields_for( object_name, *(args << options), &proc )
concat( "</ul>" )
concat( '</form>' )
end
|