Accessing Rails helper method with_output_buffer

Hi all,

I cannot figure out how to correctly use the with_output_buffer helper method (located in ActionView::Helpers::CaptureHelper) inside a custom FormBuilder.

Below follows a simplified example.

I'm trying to achieve the following behavior in an ERB as suggested in the form_for helper docs in the Rails source:

You need to use builder's @template ivar - this is the view that was being rendered so has all the helpers you need (if you look at how a form builder's radio_button, check_box etc. methods are implemented, they just call the corresponding method on @template)

Fred

Thank you very much, Frederick!

I'm into my day 5 digging into Rails rendering internals (writing a plugin) but I didn't think of that. This part of Rails seems like it needs some tidying.. More questions arise but I'll try to answer them myself first.

Thank you! Martin

I´m trying to run Hobo 1.3.0.pre31, with Ruby 1.9.2 and Rails 3.1.0, on Ubunto 10.04. So far, everytime I tried to start a new Hobo project, it failed at the time of the initial migration with the message "rake aborted!", followed by: "AssociationCollection is not a class

/usr/local/lib/ruby/gems/1.9.1/gems/hobo-1.3.0.pre31/lib/hobo/extensions/active_record/associations/collection.rb:3:in `<module:Associations>': AssociationCollection is not a class (TypeError)   from /usr/local/lib/ruby/gems/1.9.1/gems/hobo-1.3.0.pre31/lib/hobo/extensions/active_record/associations/collection.rb:2:in `<module:ActiveRecord>'   from /usr/local/lib/ruby/gems/1.9.1/gems/hobo-1.3.0.pre31/lib/hobo/extensions/active_record/associations/collection.rb:1:in `<top (required)>'   from /usr/local/lib/ruby/gems/1.9.1/gems/activesupport-3.1.0/lib/active_support/dependencies.rb:240:in `require'   from /usr/local/lib/ruby/gems/1.9.1/gems/activesupport-3.1.0/lib/active_support/dependencies.rb:240:in `block in require'   from /usr/local/lib/ruby/gems/1.9.1/gems/activesupport-3.1.0/lib/active_support/dependencies.rb:223:in `block in load_dependency'   from /usr/local/lib/ruby/gems/1.9.1/gems/activesupport-3.1.0/lib/active_support/dependencies.rb:640:in `new_constants_in'   from /usr/local/lib/ruby/gems/1.9.1/gems/activesupport-3.1.0/lib/active_support/dependencies.rb:223:in `load_dependency'   from /usr/local/lib/ruby/gems/1.9.1/gems/activesupport-3.1.0/lib/active_support/dependencies.rb:240:in `require'   from /usr/local/lib/ruby/gems/1.9.1/gems/hobo-1.3.0.pre31/lib/hobo/engine.rb:27:in `block in <class:Engine>'   from /usr/local/lib/ruby/gems/1.9.1/gems/activesupport-3.1.0/lib/active_support/lazy_load_hooks.rb:36:in `instance_eval'   from /usr/local/lib/ruby/gems/1.9.1/gems/activesupport-3.1.0/lib/active_support/lazy_load_hooks.rb:36:in `execute_hook'   from /usr/local/lib/ruby/gems/1.9.1/gems/activesupport-3.1.0/lib/active_support/lazy_load_hooks.rb:43:in `block in run_load_hooks'   from /usr/local/lib/ruby/gems/1.9.1/gems/activesupport-3.1.0/lib/active_support/lazy_load_hooks.rb:42:in `each'   from /usr/local/lib/ruby/gems/1.9.1/gems/activesupport-3.1.0/lib/active_support/lazy_load_hooks.rb:42:in `run_load_hooks'   from /usr/local/lib/ruby/gems/1.9.1/gems/activerecord-3.1.0/lib/active_record/base.rb:2184:in `<top (required)>'   from /usr/local/lib/ruby/gems/1.9.1/gems/activerecord-3.1.0/lib/active_record/migration.rb:633:in `initialize'   from /usr/local/lib/ruby/gems/1.9.1/gems/hobo_fields-1.3.0.pre31/lib/generators/hobo/migration/migration_generator.rb:94:in `new'   from /usr/local/lib/ruby/gems/1.9.1/gems/hobo_fields-1.3.0.pre31/lib/generators/hobo/migration/migration_generator.rb:94:in `migrations_pending?'   from /usr/local/lib/ruby/gems/1.9.1/gems/hobo_fields-1.3.0.pre31/lib/generators/hobo/migration/migration_generator.rb:47:in `migrate'   from /usr/local/lib/ruby/gems/1.9.1/gems/thor-0.14.6/lib/thor/task.rb:22:in `run'   from /usr/local/lib/ruby/gems/1.9.1/gems/thor-0.14.6/lib/thor/invocation.rb:118:in `invoke_task'   from /usr/local/lib/ruby/gems/1.9.1/gems/thor-0.14.6/lib/thor/invocation.rb:124:in `block in invoke_all'   from /usr/local/lib/ruby/gems/1.9.1/gems/thor-0.14.6/lib/thor/invocation.rb:124:in `each'   from /usr/local/lib/ruby/gems/1.9.1/gems/thor-0.14.6/lib/thor/invocation.rb:124:in `map'   from /usr/local/lib/ruby/gems/1.9.1/gems/thor-0.14.6/lib/thor/invocation.rb:124:in `invoke_all'   from /usr/local/lib/ruby/gems/1.9.1/gems/thor-0.14.6/lib/thor/group.rb:226:in `dispatch'   from /usr/local/lib/ruby/gems/1.9.1/gems/thor-0.14.6/lib/thor/invocation.rb:109:in `invoke'   from /usr/local/lib/ruby/gems/1.9.1/gems/hobo-1.3.0.pre31/lib/generators/hobo/setup_wizard/setup_wizard_generator.rb:196:in `generate_migration'   from /usr/local/lib/ruby/gems/1.9.1/gems/thor-0.14.6/lib/thor/task.rb:22:in `run'   from /usr/local/lib/ruby/gems/1.9.1/gems/thor-0.14.6/lib/thor/invocation.rb:118:in `invoke_task'   from /usr/local/lib/ruby/gems/1.9.1/gems/thor-0.14.6/lib/thor/invocation.rb:124:in `block in invoke_all'   from /usr/local/lib/ruby/gems/1.9.1/gems/thor-0.14.6/lib/thor/invocation.rb:124:in `each'   from /usr/local/lib/ruby/gems/1.9.1/gems/thor-0.14.6/lib/thor/invocation.rb:124:in `map'   from /usr/local/lib/ruby/gems/1.9.1/gems/thor-0.14.6/lib/thor/invocation.rb:124:in `invoke_all'   from /usr/local/lib/ruby/gems/1.9.1/gems/thor-0.14.6/lib/thor/group.rb:226:in `dispatch'   from /usr/local/lib/ruby/gems/1.9.1/gems/thor-0.14.6/lib/thor/base.rb:389:in `start'   from /usr/local/lib/ruby/gems/1.9.1/gems/railties-3.1.0/lib/rails/generators.rb:168:in `invoke'   from /usr/local/lib/ruby/gems/1.9.1/gems/railties-3.1.0/lib/rails/commands/generate.rb:12:in `<top (required)>'   from /usr/local/lib/ruby/gems/1.9.1/gems/activesupport-3.1.0/lib/active_support/dependencies.rb:240:in `require'   from /usr/local/lib/ruby/gems/1.9.1/gems/activesupport-3.1.0/lib/active_support/dependencies.rb:240:in `block in require'   from /usr/local/lib/ruby/gems/1.9.1/gems/activesupport-3.1.0/lib/active_support/dependencies.rb:223:in `block in load_dependency'   from /usr/local/lib/ruby/gems/1.9.1/gems/activesupport-3.1.0/lib/active_support/dependencies.rb:640:in `new_constants_in'   from /usr/local/lib/ruby/gems/1.9.1/gems/activesupport-3.1.0/lib/active_support/dependencies.rb:223:in `load_dependency'   from /usr/local/lib/ruby/gems/1.9.1/gems/activesupport-3.1.0/lib/active_support/dependencies.rb:240:in `require'   from /usr/local/lib/ruby/gems/1.9.1/gems/railties-3.1.0/lib/rails/commands.rb:28:in `<top (required)>'   from script/rails:6:in `require'   from script/rails:6:in `<main>'

Please reply help me