Topic: what? controller method is undefined?

Helper method is not available to the controller...

module BookHelper
  def keep(id)
    ...
  end
end

class BookController < ApplicationController
  def export
    # Why this one gives an undefined error ??
    keep( 3 )

    # I even tried this too
    # BookHelper::keep( 3 )
  end
end


Thanks

Last edited by inancgumus (2007-01-22 11:35:49)

Re: what? controller method is undefined?

I'm on my work computer so I don't have any Ruby code in front of me but I think you just need to add a require line:

[code:ruby]
class BookController < ApplicationController
  require BookHelper

  def export
....
[/code]

Re: what? controller method is undefined?

that does the trick:

# in the controller, i wrote:
include Book::BookHelper

but the above way is a neat one to do this ?

Last edited by inancgumus (2007-01-22 13:28:31)

Re: what? controller method is undefined?

I'm glad you got it working. I don't know what the difference is between require and include. Like I said, I don't have any of my code handy. I do have my electronic copy of Agile Web Deb With RoR and I can report that they seem to use require a lot more than they use include.

Re: what? controller method is undefined?

"include" is for including a module into a class, so that is the right one to use. I don't think you would need the "Book::" prefix though:

include BookHelper

"require" is for loading a Ruby file.

Railscasts - Free Ruby on Rails Screencasts

Re: what? controller method is undefined?

Yes, it works without the prefix too, great.

Last edited by inancgumus (2007-01-22 14:11:07)