David Trasbo wrote:
Actually I think I'm close to a solution now. I made these two methods:
def fields_for_setting(namespace, name)
id = "settings_#{namespace}_#{name}_"
m = Builder::XmlMarkup.new :indent => 2
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
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|
f.label :value, label, :index => nil, :for => id+"value"
f.text_field :value, :index => nil, :id => id+"value"
end
end
In my view I'm calling the second method (text_field_for_setting) like
this:
= text_field_for_setting(:site, :owner)
The method that is called here then calls my first method
(fields_for_setting) with a block. This actually works fine, but for
some reason that I can't figure out (I hope you can help me) It only the
LAST line of the block that is passed to fields_for_setting that shows
up.
In other words, even though I declare both a label and a text field,
only the text field shows up. How comes?
--
Posted via http://www.ruby-forum.com/.