Include a Class in another model / class / lib

Posted by jaycode on Stack Overflow See other posts from Stack Overflow or by jaycode
Published on 2010-06-16T09:03:10Z Indexed on 2010/06/16 9:12 UTC
Read the original article Hit count: 196

Filed under:
|
|
|

I need to use function "image_path" in my lib class. I tried this (and couple of other variations):

class CustomHelpers::Base
  include ActionView::Helpers::AssetTagHelper
  def self.image_url(source)
    abs_path = image_path(source)
    unless abs_path =~ /^http/
      abs_path = "#{request.protocol}#{request.host_with_port}#{abs_path}"
    end
    abs_path
  end
end

But it didn't work. Am I doing it right?

Another question is, how do I find the right class to include? For example if I look at this module: http://api.rubyonrails.org/classes/ActionView/Helpers/AssetTagHelper.html is there a rule of thumb how to include that module in a model / library / class / anything else ?

© Stack Overflow or respective owner

Related posts about ruby-on-rails

Related posts about ruby