I’m using the latest trunk of 1.2-ish, and I’m wondering how to do what
I want to do. I am using a form_for :builder I wrote, simply called
TableFormBuilder after the rails cookbook, and want to be able to
present help icons automatically. I want these icons to appear next to
form fields I am rendering.
For example, I have this method in helpers/table_form_builder.rb:
This enables you to use select groups like text fields
def select_group(object_name, choices, options = {}, html_options =
{})
human = options.delete(:human) || object_name.to_s.gsub(/_id$/,
‘’).humanize
if options.delete(:required)
human = human.required
end
@template.content_tag(‘tr’,
@template.content_tag(‘td’, human, {‘class’ => ‘label’}) +
@template.content_tag(‘td’, select(object_name, choices, options,
html_options),
{‘class’ => ‘field’}) +
help_icon(object_name))
end
In my view, I call this as:
f.select_group(:layout_id, etc …)
Specificially, I’m focusing on the help_icon(object_name) method shown
above. This is attached to a help table, which looks up topics based on
the string passed in. This works fine.
The help_icon method in TableFormBuilder is this:
This creates a link of system help exists, otherwise bypasses
def help_icon(help_topic)
help =
SystemHelp.find_by_help_topic(help_topic.to_s.gsub(/_id$/,’’))
if help
render :layout => false, :partial => true
else
return ‘’
end
end
That doesn’t work. The error is:
undefined method `render’ for #TableFormBuilder:0xb79d9094
It appears that render() is not available in the form_for :builder
context.
Is there another way to accomplish this? I really want to attach it to
the builder, rather than having to say “+ help_icon” in all my views.
Thanks,
Nate