A Ruby block question

Hi –

On Fri, 17 Oct 2008, David T. wrote:

def fields_for_setting(namespace, name)
id+“namespace”)
id = “settings_#{namespace}#{name}
fields_for_setting(namespace, name) do |f|
concat f.label :value, label, :index => nil, :for => id+“value”
concat f.text_field :value, :index => nil, :id => id+“value”
end
end

So, I’m concatenating the label and text field inside the
fields_for_setting block. But the fields_for_setting block doesn’t have
any effect at all! I think it’s because fields_for_setting is only
returning the

and hidden fields, 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.

David

On Fri, Oct 17, 2008 at 7:32 PM, David T. [email protected]
wrote:

But, come on! There must be a better solution. This doesn’t seem very
idiomatic to me. Nobody got a better idea?

I skipped through most of this thread, so this might be off target,
but have you looked into using Rails’ “capture” helper to get a block
of Haml into a string?
http://api.rubyonrails.com/classes/ActionView/Helpers/CaptureHelper.html#M001750

Henrik — wrote:

But, come on! There must be a better solution. This doesn’t seem very
idiomatic to me. Nobody got a better idea?

I skipped through most of this thread, so this might be off target,
but have you looked into using Rails’ “capture” helper to get a block
of Haml into a string?
Peak Obsession

No, actually I haven’t. Thank you very much for your suggestion. I’m
using that now. (: