audits1984: undefined method `assets' for #

As we’re not using # require "sprockets/railtie" - I’ve encountered a problem with audits1984 engine: undefined method 'assets' for #<Rails::Application::Configuration

I fixed it locally by conditional statement

initializer "audits1984.assets.precompile" do |app|
  if app.config.respond_to?(:assets)
    app.config.assets.precompile << "audits1984_manifest.js"
  end
end

Would that be a problem to merge it into code base 🥺 ? Cheers!

About this issue

  • Original URL
  • State: open
  • Created 3 years ago
  • Comments: 18 (8 by maintainers)

Commits related to this issue

Most upvoted comments

Thank you so much @rosa 🙏 🙏🙏🙏. I merged https://github.com/basecamp/audits1984/pull/61 and will release a new version with it later today.

@rosa just addressed this same problem for Mission control jobs. I’d like to use the same approach here. I’ll try to get to this but I have other things in my queue, so I’d appreciate a PR if someone feels like working on this.

We’ve had to do the same, definitely feels like something that should be fixed without forking

That did it!

Screenshot 2024-11-13 at 6 05 59 PM

It appears that the CSS requests are being mistakenly routed to our react frontend, which returns the default react HTML page. I think this is probably caused by how our Nginx is setup. I can try setting this up on a more standard Rails service we have.

Does this match what a typical path should be for the CSS request? /assets/audits1984/bulma.min-a0bcd487.css

@AlicjaCyganiewicz @nicalpi @coalest @humzahkiani-JW @jipiboily, if you want to give a try at #61 please do! I hope it fixes your issues. Basically, just add propshaft to your app with that branch.

I’ll have a look, @jorgemanrubia! 🙏 Also, @jipiboily, I realised I forgot about vite_rails in that other PR. I need to look into how that one works, as I’m not familiar with it, and see how the solution could be expanded to support it.

Nice, thanks a lot @coalest. I ended up doing something similar in the end, so it’s good to know I’m not the only one with the same issue.

@nicalpi I had the same issue and had to fork the gem with that conditional. And then added the following initializer to fix the styling of the UI.

# config/initializers/audits1984.rb

unless Rails.application.config.respond_to?(:assets)
  gem_asset_root = Audits1984::Engine.root.join("app/assets")
  tmp_asset_root = Rails.root.join("tmp/audits1984/assets")

  # Create audits1984 css and js files
  asset_files = [
    "javascripts/audits1984/application.js",
    "stylesheets/audits1984/bulma.min.css",
    "stylesheets/audits1984/application.css",
  ]

  asset_files.each do |file|
    unless (local_file = tmp_asset_root.join(file)).exist?
      local_file.dirname.mkpath
      local_file.write gem_asset_root.join(File.dirname(file)).children.map(&:read).join("\n\n")
    end
  end

  # Serve custom assets instead of audits1984's (that will 404 without the asset pipeline)
  Rails.application.config.middleware.use Rack::Static,
    urls: %w[/javascripts/audits1984 /stylesheets/audits1984 /images/audits1984],
    root: tmp_asset_root
end