administrate icon indicating copy to clipboard operation
administrate copied to clipboard

Implicit dependencies on the Rails Asset Pipeline

Open marisawallace opened this issue 11 years ago • 32 comments

When I added Administrate to my Rails app, things were broken out of the box. My app is designed to be an API backend only, and didn't include Sprockets or several other necessary Rails Asset Pipeline gems.

I'm not a Rails expert, so I can't speak to how this issue should be handled in general. But you might find it worthwhile to make these dependencies explicit within Administrate.

For reference, I was able to load the Administrate dashboard after adding the following to my Gemfile

gem 'sprockets-rails'
gem 'sass-rails'
gem 'uglifier'
gem 'coffee-rails'
gem 'jquery-rails'

(EDIT: this list is neither minimal nor exhaustive-- I just copy/pasted from the Rails Guides. As grayson mentioned below, the 'coffee-rails' gem shouldn't be needed.)

and uncommenting the line

gem 'sprockets-rails'

in /config/application.rb.

marisawallace avatar Nov 06 '15 12:11 marisawallace

@maxkwallace good point - we can fix that. Give me a couple minutes and I can have a PR up.

c-lliope avatar Nov 06 '15 12:11 c-lliope

@maxkwallace can you narrow that list down a little more? For example, Administrate doesn't use any CoffeeScript. If you remove that from the list, does the app still error out?

c-lliope avatar Nov 06 '15 13:11 c-lliope

I've opened up #174, which hopefully fixes this. Can you try pointing your Gemfile at:

gem "administrate", github: "thoughtbot/administrate", branch: "gw-explicit-asset-dependencies"

and see if it works?

c-lliope avatar Nov 06 '15 13:11 c-lliope

@graysonwright Gladly-- I'll give that a shot. Your question above is well-warrented btw... I just copied those gems from the Rails guides, so the list is neither minimal nor exhaustive. I should have clarified that in my original post.

marisawallace avatar Nov 06 '15 13:11 marisawallace

@graysonwright Here's the steps I followed:

  • Created a new branch off of master in my app
  • Added gem "administrate", github: "thoughtbot/administrate", branch: "gw-explicit-asset-dependencies" to my Gemfile
  • bundle
  • Ran rails generate administrate:install
  • Saw the following error (same as before):
mkw@user-computer:~/sw/shearwater/rails$ rails generate administrate:install
/home/mkw/.rvm/gems/ruby-2.2.3@shearwater/gems/inline_svg-0.6.1/lib/inline_svg.rb:25:in `asset_finder=': Asset Finder should implement the #find_asset method (InlineSvg::Configuration::Invalid)
  from /home/mkw/.rvm/gems/ruby-2.2.3@shearwater/gems/inline_svg-0.6.1/lib/inline_svg/railtie.rb:15:in `block (2 levels) in <class:Railtie>'
  from /home/mkw/.rvm/gems/ruby-2.2.3@shearwater/gems/inline_svg-0.6.1/lib/inline_svg.rb:55:in `configure'
  from /home/mkw/.rvm/gems/ruby-2.2.3@shearwater/gems/inline_svg-0.6.1/lib/inline_svg/railtie.rb:12:in `block in <class:Railtie>'
  from /home/mkw/.rvm/gems/ruby-2.2.3@shearwater/gems/activesupport-4.2.4/lib/active_support/lazy_load_hooks.rb:36:in `call'
...
  • Uncommented require "sprockets/railtie" in my config/application.rb
  • Re-ran rails generate administrate:install
  • Started my server-- everything looks good!

I'm not sure if it would make sense to handle the 'sprockets/railtie' require in your generator, but you'll probably want to add a comment about that to the docs, at least.

marisawallace avatar Nov 06 '15 13:11 marisawallace

oh, cool. mind trying one more time for me? I think we can get it if I add that require statement to the Administrate engine file – like this.

c-lliope avatar Nov 06 '15 13:11 c-lliope

@graysonwright Not at all! I'll give it another shot.

marisawallace avatar Nov 06 '15 13:11 marisawallace

Worked for me but only with require "sprockets/railtie" in my config/application.rb

Sorry to butt in, I'm in a very similar situation to @maxkwallace so happy to help where I can.

tomgatzgates avatar Nov 06 '15 13:11 tomgatzgates

@graysonwright I'm trying to test this but having trouble verifying that bundler is downloading the updated branch after your recent commit

Following the same steps as before didn't work (same error as the one I posted above), but I suspect that I might just not have the updated version of the gem. I tried

gem "administrate", github: "thoughtbot/administrate", branch: "gw-explicit-asset-dependencies", ref: 'bfb43f43f5955cbb1c4c0026a8554e8960699ccc'

and then ran gem unpack administrate in an attempt to inspect my local copy of the source. I still don't see the line

require "sprockets/railtie"

in my unpacked copy of lib/administrate/engine.rb.

marisawallace avatar Nov 06 '15 14:11 marisawallace

hmm, maybe bundle update administrate ?

c-lliope avatar Nov 06 '15 14:11 c-lliope

it might be that your Gemfile.lock has it locked on the previous commit.

c-lliope avatar Nov 06 '15 14:11 c-lliope

if that doesn't work, I'd try gem uninstall administrate, delete your Gemfile.lock, and then try to do a fresh bundle install.

c-lliope avatar Nov 06 '15 14:11 c-lliope

A secondary issue i've noticed from this implantation route (API app)

NoMethodError in Admin::UsersController#index

undefined method `paginate' for #<User::ActiveRecord_Relation:0x...


@resources = User.all.paginate(10, params[:page])

tomgatzgates avatar Nov 06 '15 14:11 tomgatzgates

oh, interesting. @tomgatzgates are you using any pagination gems in your app that might be conflicting with Kaminari?

c-lliope avatar Nov 06 '15 14:11 c-lliope

also, I think I might need to start up an API-only app to test this with. Did you start from rails-api?

c-lliope avatar Nov 06 '15 14:11 c-lliope

@tomgatzgates - you might want to check out #158 for the paginate issue. Sounds similar to something we found before.

c-lliope avatar Nov 06 '15 14:11 c-lliope

@graysonwright Thanks, I'll take a look. Using grape-kaminari so perhaps that. I'll update if I find anything new

tomgatzgates avatar Nov 06 '15 14:11 tomgatzgates

@graysonwright On a fresh branch:

  • gem uninstall administrate
  • rm Gemfile.lock
  • bundle install
  • Added gem "administrate", github: "thoughtbot/administrate", branch: "gw-explicit-asset-dependencies" to my Gemfile.
  • bundle install
  • rails generate administrate:install

I still see the error:

/home/mkw/.rvm/gems/ruby-2.2.3@shearwater/gems/inline_svg-0.6.1/lib/inline_svg.rb:25:in `asset_finder=': Asset Finder should implement the #find_asset method (InlineSvg::Configuration::Invalid)
    from /home/mkw/.rvm/gems/ruby-2.2.3@shearwater/gems/inline_svg-0.6.1/lib/inline_svg/railtie.rb:15:in `block (2 levels) in <class:Railtie>'
    from /home/mkw/.rvm/gems/ruby-2.2.3@shearwater/gems/inline_svg-0.6.1/lib/inline_svg.rb:55:in `configure'
...

marisawallace avatar Nov 06 '15 14:11 marisawallace

ok - I'll create my own repo to play around with and see if I can get it working. Thanks for helping debug this!

c-lliope avatar Nov 06 '15 14:11 c-lliope

Glad to help-- thanks for the prompt replies!

marisawallace avatar Nov 06 '15 14:11 marisawallace