Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

uninitialized constant Slim::RailsTemplate (NameError) #915

Open
kallesuomala opened this issue Mar 13, 2023 · 5 comments
Open

uninitialized constant Slim::RailsTemplate (NameError) #915

kallesuomala opened this issue Mar 13, 2023 · 5 comments

Comments

@kallesuomala
Copy link

kallesuomala commented Mar 13, 2023

After upgrading Slim 4.1.0 -> 5.1.0 on my Rails app, I get the following error from the config/initializers/slim.rb:3

Slim::RailsTemplate.set_options streaming: false

uninitialized constant Slim::RailsTemplate (NameError)

Removing the line gets rid of the error, but how can I disable http streaming with the new version?

@tagliala
Copy link
Contributor

I can see that the initialization of Slim::RailsTemplate has been put in an ActiveSupport.on_load(:action_view) block

Ref:

ActiveSupport.on_load(:action_view) do
Slim::RailsTemplate = Temple::Templates::Rails(Slim::Engine,

Probably the initializer should be edited accordingly (add an on_load block), as well as the readme

- Slim::RailsTemplate.set_options streaming: false
+ ActiveSupport.on_load(:action_view) do
+   Slim::RailsTemplate.set_options streaming: false
+ end

@kallesuomala
Copy link
Author

kallesuomala commented Mar 13, 2023

@tagliala The above code does not work for me, since Slim::RailsTemplate has been put into lib/slim/railitie.rb. It appears that lib/railities does not get loaded at all since Rails::Railitie is not defined. I'm not very familiar with all of this but does the following mean that Rails::Railities would have to be defined within my Rails app in order to lib/slim/railitie.rb to get loaded?

require 'slim/railtie' if defined?(Rails::Railtie)

@tagliala
Copy link
Contributor

tagliala commented Mar 13, 2023

If you replace the initializer at config/initializers/slim.rb with

ActiveSupport.on_load(:action_view) do
  Slim::RailsTemplate.set_options streaming: false
end

it doesn't work?

What is the error?

@kallesuomala
Copy link
Author

It does not. I get the same error uninitialized constant Slim::RailsTemplate (NameError)

@kallesuomala
Copy link
Author

kallesuomala commented Mar 16, 2023

I got it to work with the following in config/initializers/slim.rb Should this be updated into the readme?

Rails.application.config.after_initialize do
  ActiveSupport.on_load(:action_view) do
    Slim::RailsTemplate.set_options streaming: false
  end
end

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants