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

Cannot remove asset dependency path in Rails 5 #314

Closed
smarquez1 opened this issue Mar 5, 2016 · 2 comments
Closed

Cannot remove asset dependency path in Rails 5 #314

smarquez1 opened this issue Mar 5, 2016 · 2 comments

Comments

@smarquez1
Copy link

Hi, I created this issue since #132 is locked.
I have the exact same issue of the link above but the mentioned workaround does not appear to be working on Rails 5 (beta 3). The assets path is empty while trying to access from an initializer. Do you know any workaround for this?

Rails.configuration.assets.paths.reject! do |path|
  path.include?('rails-assets-bootstrap')
end
@rjocoleman
Copy link

For anyone searching here's the thing:

In your Rails 5 initializer you don't have all the paths populated yet, so we want to do this rejection after the initialization is complete.

Rails.application.config.after_initialize do
  Rails.application.config.assets.paths.reject! do |path|
      path.include? 'rails-assets-bootstrap'
  end
end

However this is a little simplistic, as noted in another issue (#282) this will reject rails-assets-bootstrap and rails-assets-bootstrap-datepicker etc.

Here's an example that lets you set an array of gem names to reject, it includes the gem version in the final check to safely reject specific gems only:

Rails.application.config.after_initialize do
  # add the gem names you wish to reject to the below array
  excluded_gem_names = ['rails-assets-bootstrap']

  excluded_gem_full_names = Gem::Specification.select { |g| excluded_gem_names.include? g.name }.flat_map { |a| a.full_name }
  Rails.application.config.assets.paths.reject! do |path|
    excluded_gem_full_names.any? { |gem_name| path.include? gem_name }
  end
end

@fbacall
Copy link

fbacall commented Jul 5, 2019

I couldn't get the above to work in Rails 5.2, but using the to_prepare hook instead of after_initialize fixed it for me:

Rails.application.config.to_prepare do
  Rails.configuration.assets.paths.reject! do |path|
    path =~ /rails-assets-bootstrap-[0-9]/
  end
end

@smarquez1 smarquez1 closed this as not planned Won't fix, can't repro, duplicate, stale May 22, 2024
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

3 participants