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: =========<%= form_for @object, :builder => MyFormBuilder do |my_form| %> <%= my_form.my_dummy_div_wrapper do %> <%= ... %> <%= end %> <% end %> ========= Here''s the helper: =========module MyHelper class MyFormBuilder < ActionView::Helpers::FormBuilder def my_dummy_div_wrapper(&block) output = "<div>".html_safe # here I should use with_output_buffer to correctly get the block''s output output.safe_concat(with_output_buffer &block) output.safe_concat "</div>" output end end end ========= Inside the MyFormBuilder methods, there''s no with_output_buffer method defined so I cannot use it (and a bunch of other Rails helpers; cannot render a partial, etc..). I already spent two days studying the Rails source, tried lots of things, no luck so far. I don''t think what I''m trying to accomplish is wrong: I''m not calling view helper methods from models etc. Any help a life saver! Thank you, Martin -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Frederick Cheung
2011-Sep-13 10:15 UTC
Re: Accessing Rails helper method with_output_buffer
On Sep 13, 11:00 am, Gogov <mgo...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> 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: > > > Inside the MyFormBuilder methods, there''s no with_output_buffer method > defined so I cannot use it (and a bunch of other Rails helpers; cannot > render a partial, etc..).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 -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
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 On Sep 13, 1:15 pm, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On Sep 13, 11:00 am, Gogov <mgo...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > 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: > > > Inside the MyFormBuilder methods, there''s no with_output_buffer method > > defined so I cannot use it (and a bunch of other Rails helpers; cannot > > render a partial, etc..). > > 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-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
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 -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.