How can I access render_partial from a class that does not inherit from ActionController? I tried using "include ActionView::Partials" in my class definition, but I still get "undefined method ''render_partial''". I''m sure this is really simple, any suggestions? Thanks, Steve
> > How can I access render_partial from a class that does not inherit from > ActionController? I tried using "include ActionView::Partials" in my class > definition, but I still get "undefined method ''render_partial''". I''m sure > this is really simple, any suggestions?Anyone have any thoughts on this? I don''t understand why it shouldn''t work, but it doesn''t. Steve
Gavin Sinclair
2005-Apr-19 00:18 UTC
Re: Accessing render_partial from outside controller?
On Tuesday, April 19, 2005, 3:49:28 AM, Steve wrote:>> >> How can I access render_partial from a class that does not inherit from >> ActionController? I tried using "include ActionView::Partials" in my class >> definition, but I still get "undefined method ''render_partial''". I''m sure >> this is really simple, any suggestions?> Anyone have any thoughts on this? I don''t understand why it shouldn''t work, > but it doesn''t.My experience of this sort of thing is that it''s tricky. For a start, the controller''s implementation of render_partial comes from ActionController::Base, not ActionView::Partials. Even then, though, those methods tend to rely on some context that you can''t (easily) see, like instance variables. Here''s some code that will give you an idea. I wanted to use "link_to" from my own class, so I tried class FooHelperClass include ActionView::Helpers::UrlHelper def initialize(widget) @w = widget end def foo link_to "foo", :action => ''something'' end end Then I got an error when link_to was called. I dug through the source and found that it was because the variable @controller was not set. (See what I mean about context?) So I did changed this method: def initialize(widget, actionview) @w = widget @controller = actionview.controller end and it worked. This is a pretty ugly path to tread. I''m going to see if I can make it look respectable and reusable somehow. Cheers, Gavin