On 27 November 2010 09:16, Rob Lacey <cont...@robl.me> wrote: > I'm judging from your response that you would you argue that using a > Rails view helper inside another view helper is wrong then? I would > say this isn't crazy its just trying to DRY up a small form (just a > button) I am using in lots of different places. > > I found the solution in the end. > > module MyHelper > > def button_thing_attempt_2 > with_output_buffer(form_for(Button.new) do |f| > concat(f.submit 'Push') > end) > end > > end
I think it would be more conventional to put the form in a partial to achieve the re-usability. By the way it is considered bad form (!) to access a model directly from the view or view helper. It is better in the controller to say @button = Button.new then use @button in the view. Colin > > RobL > > On 27 November 2010 03:16, daze <dmonopol...@gmail.com> wrote: >> Whoa whoa whoa. form_for is for the VIEW. It generates html. >> Specifcally, it generates <form> tags and etc... >> >> >> On Nov 26, 2:35 pm, RobL <pgdst...@gmail.com> wrote: >>> Hi there, >>> >>> I'm having an awful lot of trouble trying to use form_for inside a >>> helper. Any ideas how to get this to work? >>> >>> module MyHelper >>> >>> def button_thing_attempt_1 >>> form_for(Button.new) do |f| >>> f.submit 'Push' >>> end >>> end >>> >>> def button_thing_attempt_2 >>> with_output_buffer(form_for(Button.new) do |f| >>> f.submit 'Push' >>> end) >>> end >>> >>> end >>> >>> While I get attempt 2 to render the form, the submit button is >>> missing. I'm just not quite sure how to really capture the complete >>> output of form_for. >>> >>> Many thanks for any help here >>> >>> RobL >> >> -- >> 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-t...@googlegroups.com. >> To unsubscribe from this group, send email to >> rubyonrails-talk+unsubscr...@googlegroups.com. >> For more options, visit this group at >> http://groups.google.com/group/rubyonrails-talk?hl=en. >> >> > > > > -- > Rob Lacey > cont...@robl.me > http://www.robl.me > > -- > 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-t...@googlegroups.com. > To unsubscribe from this group, send email to > rubyonrails-talk+unsubscr...@googlegroups.com. > For more options, visit this group at > http://groups.google.com/group/rubyonrails-talk?hl=en. > > -- 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-t...@googlegroups.com. To unsubscribe from this group, send email to rubyonrails-talk+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.