From: David Trasbo Date: 2008-10-18T02:32:39+09:00 Subject: Re: A Ruby block question David A. Black wrote: >> ... but how is this solved? > > Try this: > > fields_for_setting(namespace, name) do |f| > f.label :value, label, :index => nil, :for => id+"value" + > f.text_field :value, :index => nil, :id => id+"value" > end > > i.e., returning a string from the block. syntax error, unexpected tSYMBEG, expecting kEND But I grabbed your concept, this actually works: def fields_for_setting(namespace, name) output = "" id = "settings_#{namespace}_#{name}_" m = Builder::XmlMarkup.new(:indent => 2, :target => output) fields_for "settings[]", setting = Setting.find_or_initialize_by_namespace_and_name(namespace, name) do |f| m.p do unless setting.new_record? m << f.hidden_field(:id, :index => nil, :id => id+"id") end m << f.hidden_field(:namespace, :index => nil, :id => id+"namespace") m << f.hidden_field(:name, :index => nil, :id => id+"name") m << yield(f) end end puts output end def text_field_for_setting(namespace, name, label=nil) namespace = namespace.to_s name = name.to_s label ||= "#{namespace.capitalize} #{name}" id = "settings_#{namespace}_#{name}_" fields_for_setting(namespace, name) do |f| o = f.label(:value, label, :index => nil, :for => id+"value") o << f.text_field(:value, :index => nil, :id => id+"value") end end But, come on! There must be a better solution. This doesn't seem very idiomatic to me. Nobody got a better idea? -- Posted via http://www.ruby-forum.com/.