Stefano Crocco wrote:
>> In other words I need to put user-defined input in between some
>> pre-defined content. How can I approach that?
>
> If I understand correctly what you want to do, you don't need to do
> anything
> special:
>
> def my_method
> puts "predefined text 1"
> puts yield
> puts "predefined text 2"
> end
My method looks like this:
def fields_for_setting(namespace, name, &block)
namespace = namespace.to_s
name = name.to_s
id = "settings_#{namespace}_#{name}_"
m = Builder::XmlMarkup.new :indent => 2
fields_for "settings[]", setting =
Setting.find_or_initialize_by_namespace_and_name(n amespace, 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")
#puts yield f???
end
end
end
The problem is, I'm using Builder::XmlMarkup and the fields_for from
Rails. I want to put some hidden fields AND the text fields defined by
the block into a <p> tag. That means I need to be able to access the f
object provided by fields_for and use it in this method's block.
But how?
--
Posted via
http://www.ruby-forum.com/.