Skip to content

Instantly share code, notes, and snippets.

@skyporter
Created September 8, 2021 07:39
Show Gist options
  • Save skyporter/d078f36ea8c82af92613616686553ec2 to your computer and use it in GitHub Desktop.
Save skyporter/d078f36ea8c82af92613616686553ec2 to your computer and use it in GitHub Desktop.
Rails render view outside controller
class FakeController < ActionController::Base
include ApplicationHelper
def current_user
@current_user ||= User.find(params[:user_id])
end
end
renderer = FakeController.renderer.new(
'action_dispatch.request.path_parameters' => {
user_id: 4685
}
)
renderer.render(file: 'shared/events/index.pdf.erb', layout: "layouts/pdf", assigns: {events: Event.where(id: 463385), organization: Organization.find(42)})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment