Sharing helpers between controllers
ryan / Wed, 24 Jan 2007 18:44:00 GMT
This article has moved over to our sister spin-off blog, RubyJudo, which focuses on more arcane technical topics than NotRocketSurgery.
ryan / Wed, 24 Jan 2007 18:44:00 GMT
This article has moved over to our sister spin-off blog, RubyJudo, which focuses on more arcane technical topics than NotRocketSurgery.
Agile 2, p472, “Sharing Helpers”
Lots of other good stuff in there :)
Well, haven’t quite gotten around to rereading the Agile book in its 2nd edition, though the new version it is sitting on my desk now. And I do sort of have that intent. It’s on the someday/maybe list.
Oh well. This helper inclusion business was news to me. And for some reason it was hard to come up with the google terms to get my answer. So I thought I’d add to the keyword heap.
Asking JD > #rubyonrails :)
An alternative, albeit an ugly one, is to do your shared helpers in app/controllers/application.rb or app/helpers/application_helpers.rb.
I’m doing that now while I’m in early development mode, but plan on “extracting” things out it into more logical modules or into more specific helpers down the line.
Cheers, Walter
I noticed this technique while going through the Beast source – I didn’t know what it did until reading this, so thank you!
By the way, the last paragraph, should it say:
“You can now use all the helper methods in SubscriptionHelper anywhere in an AccountController template.”
Thanks again,
Keeran
Thanks Keeran! :)
One difficulty seems to come from rendering templates. Unless I’m doing something wrong you now have to specify them by the root of the helper directory such as render(:partial => ’/controller/template’) as opposed to render(:partial => ‘template’) or they can’t be found.