Hi,
I have a long running task which generates JavaScript to files and I am
hoping to move this to a backgroundrb worker. The javascript is
currently generated with call to render_to_string:
File.open(File.join(target_folder, ''all.js''), "w")
do |file|
file.puts(render_to_string :partial =>
''partials/shared/javascript/tags'', :locals => { :namespaces
=>
@namespaces, :tags => @tags, :parent_tags => @parent_tags, :show_counts
=> true })
end
It seems that the render_to_string is not available to the worker. Does
anyone know of a better way to achieve this using a partial? I can fall
back to generating the javascript text in a method, but this seems quite
an ugly solution (although will be much more performant than my current
in process solution).
Any tips or pointers would be much appreciated.
Thanks,
GiantCranes
--
Posted via http://www.ruby-forum.com/.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---
It is possible to render an action from backgroundrb, although it''s a
bit tedious. Backgroundrb doesn''t seem to load the controller layer
when it runs - I assume this is because it''s intended for manipulating
data, and not generating views, which makes sense. Anyway, in order to
get the rendering functions working you need to create a Dummy
controller that implements a few methods that render relies on. I''ve
included a stripped down version below which *should* work, although I
haven''t tested it. The example works on the older win32 compatible
version of backgroundrb, but I haven''t tried it on the newer *nix only
version.
===================================================
class SampleWorker < BackgrounDRb::Rails
require ''action_view''
def do_work(args)
#redirect the rails default logger for active record to
backgroundrb
ActiveRecord::Base.logger= @logger
action_view ActionView::Base.new(Rails::Configuration.new.view_path, {},
DummyController.new)
action_view.render(:partial => "foo/bar")
end
end
class DummyController
def logger
@logger
end
def headers
{''Content-Type'' => ''application/xml''}
end
def response
DummyResponse.new
end
def content_type
''application/xml''
end
end
class DummyResponse
def content_type
''application/xml''
end
end
===================================================Hope that helps,
Dan
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---
Dan, Thanks! That worked well. The only slight modification was the addition of the following lines: require ''active_support'' require ''action_controller'' require ''action_view'' Thanks again, GiantCranes -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Reasonably Related Threads
- does BackgrounDRB not "know" the rails environment it is running within/in parallel with?]
- calling render_to_string outside of controller
- First call to worker method doesn''t work
- undefined method: controller_name
- rendering a partial inside another using render_to_string and (:formats) in controller