Implicit dependencies on the Rails Asset Pipeline
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.
@maxkwallace good point - we can fix that. Give me a couple minutes and I can have a PR up.
@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?
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?
@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.
@graysonwright Here's the steps I followed:
- Created a new branch off of
masterin my app - Added
gem "administrate", github: "thoughtbot/administrate", branch: "gw-explicit-asset-dependencies"to myGemfile 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 myconfig/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.
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.
@graysonwright Not at all! I'll give it another shot.
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.
@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.
hmm, maybe bundle update administrate ?
it might be that your Gemfile.lock has it locked on the previous commit.
if that doesn't work, I'd try gem uninstall administrate, delete your Gemfile.lock, and then try to do a fresh bundle install.
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])
oh, interesting. @tomgatzgates are you using any pagination gems in your app that might be conflicting with Kaminari?
also, I think I might need to start up an API-only app to test this with. Did you start from rails-api?
@tomgatzgates - you might want to check out #158 for the paginate issue. Sounds similar to something we found before.
@graysonwright Thanks, I'll take a look. Using grape-kaminari so perhaps that. I'll update if I find anything new
@graysonwright On a fresh branch:
gem uninstall administraterm Gemfile.lockbundle install- Added
gem "administrate", github: "thoughtbot/administrate", branch: "gw-explicit-asset-dependencies"to my Gemfile. bundle installrails 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'
...
ok - I'll create my own repo to play around with and see if I can get it working. Thanks for helping debug this!
Glad to help-- thanks for the prompt replies!