rails: rails 4: rendering template outside of controller raises exception in production
hello,
I want to render a template into a file in a rake task.
this was my old code (worked with rails 3):
controller = ActionController::Base.new
view = ActionView::Base.new('app/views', {}, controller)
view.render(file: 'index')
in rails 4 (in production environment) that stopped working:
ActionView::Template::Error: undefined method `parameters' for nil:NilClass
from .../actionpack-4.0.0/lib/action_controller/metal/strong_parameters.rb:510:in `params'
then I thought it would be good to simplify my code:
ActionView::Base.new('app/views').render(file: 'index')
but this does not render asset pipeline file paths correctly.
so this is my current workaround:
ActionController::Base.new.tap { |controller|
def controller.params
{} # suppress strong parameters exception
end
}.render_to_string(file: filename)
is this a rails bug or I’m doing something wrong?
thanks!
About this issue
- Original URL
- State: closed
- Created 11 years ago
- Comments: 18 (13 by maintainers)
@pseidemann We tried this just now with master and seems to be working fine. See below for output
Closing this for now. Please let me know if you see this with latest version of Rails.
cc/ @m1k3