2

I have a class (not a controller) that generates external javascript that we then store in redis and am using Rails 3.2.19. One of the views calls a helper that is located in application_helper but it is now erroring out saying that it can't find the helper.

I would think that calling ActionView::Base.new would bring in the helpers from application_helper.rb but it doesn't appear to by default. However, on production on heroku, this does work as anticipated. I guess the question is what is the path for the views created via ActionView::Base.new?

I have:

class MenuGenerator
  def self.js_external(id)
    @menu=Menu.find(id)
    str=ActionView::Base.new(
        Rails.configuration.paths["app/views"]).render(
        :partial => 'api/get_menu_3',
        :locals => { :menu => @menu, :format => 'div' })
    key='menus/' + id.to_s + '/js-external'
    $redis.set(key, str)
    return str
  end

and have tried including my application_helper via

 def self.js_external(id)
    include ApplicationHelper
    @menu=Menu.find(id)

or

class MenuGenerator
  include ApplicationHelper

but neither works. What woudl I need to add to make this helper accessible by my view?

timpone
  • 19,235
  • 36
  • 121
  • 211
  • What are you exactly trying to do with `MenuGenerator ` class? What is the purpose? is this for view or for storing data in db? – Surya Oct 29 '14 at 19:08
  • prebuild an external javascript file for an external user. It is called from a sidekiq job – timpone Oct 29 '14 at 19:09
  • After a wild laugh I realized this is actually a nice question, because it needs some deeper rails insights. I don't have time to dig in right now, but I'd suggest read the rails code and try to find out what the rails guys actually called to render a view. I'll keep track of this question, because I don't get why it would work on Heroku but not localy.. – Ninigi Oct 31 '14 at 22:30
  • @Ninigi yeah, was a bit wierd. I actually just ended up putting the functionality in models and called it a day. Life's too short – timpone Oct 31 '14 at 23:36

0 Answers0