slim-template / slim

Slim is a template language whose goal is to reduce the syntax to the essential parts without becoming cryptic.
https://slim-template.github.io
MIT License
5.29k stars 500 forks source link

uninitialized constant Slim::RailsTemplate (NameError) #915

Open kallesuomala opened 1 year ago

kallesuomala commented 1 year ago

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 commented 1 year ago

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

Ref: https://github.com/slim-template/slim/blob/b7680ab12af65400a4b78517619f5ea76714add1/lib/slim/railtie.rb#L4-L5 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 commented 1 year ago

@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?

https://github.com/slim-template/slim/blob/b7680ab12af65400a4b78517619f5ea76714add1/lib/slim.rb#L15

tagliala commented 1 year ago

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 commented 1 year ago

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

kallesuomala commented 1 year ago

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