Here's the relevant parts of a navigation-tab plugin I'm in the process
of hacking together... and I have just successfully called image_path
from it. Hope this helps someone.
class Behavior::Base
define_tags do
tag "navtab" do |tag|
tab = NavTab.new(tag.attr['label'], @request)
# ...
end
end
end
class NavTab
include ActionView::Helpers::AssetTagHelper
def initialize (label, request)
@label = label
@controller = ActionController::Base.new
@controller.request = request
p image_path('hi')
end
# ...
end
on 2006-07-18 01:38
on 2006-07-18 13:04
Jay Levitt wrote: > @controller = ActionController::Base.new > @controller.request = request I think you might have to be careful with certain helper method calls - ISTR seeing something about this on IRC. In particular some people seemed to think that url_for() might give trouble.
on 2006-07-18 19:07
Andrew Hodgkinson wrote: > Jay Levitt wrote: > >> @controller = ActionController::Base.new >> @controller.request = request > > I think you might have to be careful with certain helper method calls - > ISTR seeing something about this on IRC. In particular some people > seemed to think that url_for() might give trouble. Thanks. If I run into any weird side effects I'll start by assuming they're not my fault now... Jay
on 2006-07-18 19:21
Jay Levitt wrote: > Thanks. If I run into any weird side effects I'll start by assuming > they're not my fault now... Well, kind of; I think the "Right Answer" might be to modify the Behavior API so that Radiant's existing ActionController::Base instance gets passed in as a parameter rather than generating a new instantiation. You could default the parameter to 'nil' and use a new instance of ActionController::Base if need be, for cases where your modified Behavior code got installed into an older Radiant version.
on 2006-07-18 19:53
Andrew Hodgkinson wrote: > modified Behavior code got installed into an older Radiant version. > That'd be really nice, actually. I think that's what I was (unknowingly) asking for last month, when I got the advice to create a dummy controller. John, do you think it might be possible to get at the current ActionController from a behavior? Jay Levitt
on 2006-07-19 04:59
Jay Levitt wrote: > That'd be really nice, actually. I think that's what I was > (unknowingly) asking for last month, when I got the advice to create a > dummy controller. John, do you think it might be possible to get at the > current ActionController from a behavior? I'm open to the idea but am unsure that this is the best approach. -- John Long http://wiseheartdesign.com
on 2006-07-19 05:02
John W. Long wrote: > Jay Levitt wrote: >> That'd be really nice, actually. I think that's what I was >> (unknowingly) asking for last month, when I got the advice to create a >> dummy controller. John, do you think it might be possible to get at the >> current ActionController from a behavior? > > I'm open to the idea but am unsure that this is the best approach. What might be better, then? An awful lot of seemingly-unrelated helpers in Rails need a controller, and if a dummy one causes problems, I can't see any other option than the real controller. Jay
on 2006-07-19 05:18
Jay Levitt wrote: > John W. Long wrote: >> I'm open to the idea but am unsure that this is the best approach. > > What might be better, then? An awful lot of seemingly-unrelated helpers > in Rails need a controller, and if a dummy one causes problems, I can't > see any other option than the real controller. But that's just it. I'm not sure that behaviors should have full access to the controller. It seems like it might be better for them not to rely on that knowledge. Sorry to be ambivalent. I will need to think about this. -- John Long http://wiseheartdesign.com
Please log in before posting. Registration is free and takes only a minute.
Existing account
(Switch to SSL-encrypted connection)
NEW: Do you have a Google/GoogleMail or Yahoo account? No registration required!
Log in with Google account | Log in with Yahoo account
Log in with Google account | Log in with Yahoo account
No account? Register here.