Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Render template inside a Rails runner script
view_assigns = {widgets: Widget.all}
av = ActionView::Base.new(ActionController::Base.view_paths, view_assigns)
av.class_eval do
# include any needed helpers (for the view)
include ApplicationHelper
end
# normal render statement
content = av.render template: 'widgets/index.xlsx.axlsx'
# do something with content, such as:
File.open("/tmp/with_runner.xlsx","w+b") {|f| f.puts content }
@wilfrank84

This comment has been minimized.

Copy link

@wilfrank84 wilfrank84 commented Dec 15, 2019

@straydogstudio, this script doesn't work in a container in Docker, and I can't figure out why. Would you have any tips?

@straydogstudio

This comment has been minimized.

Copy link
Owner Author

@straydogstudio straydogstudio commented Dec 15, 2019

Can you post a gist of your Docker command etc?

@wilfrank84

This comment has been minimized.

Copy link

@wilfrank84 wilfrank84 commented Dec 15, 2019

@straydogstudio, the script is in a Job that I use with sidekiq and redis:
https://gist.github.com/wilfrank84/b6b0912d9be397e4334a3b3e02db871b

Testing outside the docker works perfectly, I suppose some dependency may be missing from the environment, but I have no idea what it could be.

Following is dockerfile:
https://gist.github.com/wilfrank84/6c7bc33ad9c352ccd1557715b1a15f9b

@bjgaynor

This comment has been minimized.

Copy link

@bjgaynor bjgaynor commented Jan 17, 2020

@straydogstudio, any word on this?

@wilfrank84, did you get it working? I'll likely have a very similar setup soon and it would be great to have an example to work with if there is one.

@straydogstudio

This comment has been minimized.

Copy link
Owner Author

@straydogstudio straydogstudio commented Jan 17, 2020

@wilfrank84 @bjgaynor I apologize I have not gotten to this. I will get to it this weekend.

@straydogstudio

This comment has been minimized.

Copy link
Owner Author

@straydogstudio straydogstudio commented Jan 19, 2020

@willfrank84 Did you have any specific errors? Your stuff is too specific for me to run it on some rails project. I notice, however, that you are using the rails runner version of the script. When you run it outside of Docker, is it by command or within sidekiq? In docker are you using Sidekiq? It's been a long while since I worked with Sidekiq. The jobs I remember had to have extra work to have what they needed. But I am not sure.

@straydogstudio

This comment has been minimized.

Copy link
Owner Author

@straydogstudio straydogstudio commented Feb 7, 2020

@willfrank Would you post your Gemfile?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment