Это работает, но методы @template являются частными, поэтому мне пришлось сделать
у меня есть этот вспомогательный метод, верно?
def table_form_field(name_or_options = nil, *args, &block)
# ...
render :partial => "snippets/table_form_field", :locals => options
end
Это хорошо, за исключением того, что иногда я хочу использовать его с конструктором форм, и для этого мне нужно будет назвать его так:
table_form_field(:foo, :form_builder => f) do |name|
f.text_field name
end
Раздражает необходимость указывать: form_builder вручную. Так что моя цель состоит в том, чтобы расширитьActionView::Helpers::FormBuilder
и добавьте новый метод к нему, вот так:
class ActionView::Helpers::FormBuilder
def table_form_field(name_or_options, options, &block)
if name_or_options.is_a?(Hash)
name_or_options[:form_builder] = self
else
options[:form_builder] = self
end
# But... how can I call the helper?
# Hmm, I'll try this:
klass = Class.new do
include ApplicationHelper
end
klass.new.send(:table_form_field, name_or_options, options, &block)
# Thank you, Mario, but your princess is in another castle!
#
# Basically, this tries to call render, and for obvious
# reasons, klass doesn't know how to render.
#
# So... what do I do?
end
end