D
David Trasbo
David said: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.newindent => 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_fieldid, :index => nil, :id => id+"id")
end
m << f.hidden_fieldnamespace, :index => nil, :id =>
id+"namespace")
m << f.hidden_fieldname, :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.labelvalue, label, :index => nil, :for => id+"value")
o << f.text_fieldvalue, :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?