Sharing helpers between controllers

ryan / Wed, 24 Jan 2007 18:44:00 GMT

Tags , , , ,  | 8 comments

This article has moved over to our sister spin-off blog, RubyJudo, which focuses on more arcane technical topics than NotRocketSurgery.

Comments / Leave a response

  • Pat Maddox said about 5 hours later:

    Agile 2, p472, “Sharing Helpers”

    Lots of other good stuff in there :)

  • Ryan Norbauer said about 10 hours later:

    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.

  • JD said about 10 hours later:

    Asking JD > #rubyonrails :)

  • Walter McGinnis said 9 days later:

    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

  • Keeran said 57 days later:

    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

  • Ryan Norbauer said 57 days later:

    Thanks Keeran! :)

  • Eleo said 119 days later:

    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.

(leave url/email »)

   Comment Markup Help