Ruby version 3.2.2
Rails version 7.0.8

Gemfile

source 'https://rubygems.org'

ruby '3.2.2'

gem 'rails', '7.0.8'
gem 'puma', '~> 4.3.9'
gem 'sass-rails', '~>6.0.0'
gem 'jquery-rails'
gem 'sprockets', '3.7.2'

# gem 'bootstrap', '~> 5.1.3'

gem 'sprockets-rails'
gem 'turbo-rails'
gem 'stimulus-rails'
gem 'hotwire-rails'
gem 'importmap-rails'
gem 'jsbundling-rails'

gem 'jbuilder', '~> 2.5'
gem 'twilio-ruby', '5.72.1'
gem 'google-authenticator-rails'
gem 'friendly_id', '~> 5.2.0'
gem 'mysql2'

...

I got some error with following.

irb(main):003:0> ActionController::Base.new.render_to_string( template: "shared/file_template/test2" )
/Users/xxx/Documents/projects/rails-project/vendor/cache/ruby/3.2.0/gems/turbo-rails-1.5.0/app/controllers/turbo/frames/frame_request.rb:36:in `turbo_frame_request_id': Could not render layout: undefined method `headers' for nil:NilClass (NoMethodError)

      request.headers["Turbo-Frame"]
             ^^^^^^^^
/Users/xxx/Documents/projects/rails-project/vendor/cache/ruby/3.2.0/gems/turbo-rails-1.5.0/app/controllers/turbo/frames/frame_request.rb:36:in `turbo_frame_request_id': undefined method `headers' for nil:NilClass (NoMethodError)

      request.headers["Turbo-Frame"]
             ^^^^^^^^

How do I fix this error?

1

There are 1 answers

1
Alex On

I'm not sure why you need to render from the console, but rails does provide a way to do this outside of the controller:

ApplicationController.renderer.render(template: "shared/file_template/test2")

https://api.rubyonrails.org/classes/ActionController/Renderer.html