8

i've started using rails 3 beta3 and I have see that the @template variable inside controllers is nil. How I can call helpers methods inside a controller? Thx

Pioz
  • 6,051
  • 4
  • 48
  • 67

1 Answers1

25

Use the view_context method instead of @template.

This is because in Rails 3 the new AbstractController was introduced.

You can read more here:

http://apidock.com/rails/AbstractController/Rendering/view_context

reto
  • 16,189
  • 7
  • 53
  • 67
Dmitry Naumov
  • 571
  • 4
  • 8
  • Hello, I am having problems with [ActionView::Helpers::FormBuilder](http://stackoverflow.com/questions/7272814/passing-actionviewhelpersformbuilder-to-a-partial). Could you paste a working example of how to use view_context. Thanks! – jalagrange Sep 08 '11 at 19:35
  • I am not sure what do you want to do, but if you want to render a form into a string in your controller you could do it like this: form_string = view_context.form_for(Article.new){|f| f.text_field :title; f.text_field :body } – Dmitry Naumov Sep 11 '11 at 00:34