Ayrad
Ayrad

Reputation: 4056

how to correctly add jquery in activeadmin with api only mode and no application.js

When trying to make a custom page in active_admin in a rails api-only app, I get the following:

$ is not defined 

I moved jquery.js into my /assets folder and imported it in my active_admin.js.coffee by adding the following line:

#= require jquery

but when I load my custom partial I get the js error.

My rails 5 app is api-only except for active admin which I'm customising so I do not have an application.js to import things in.

Upvotes: 0

Views: 925

Answers (1)

Denny Mueller
Denny Mueller

Reputation: 3615

Check your application.rb for config.api_only. If its set to true it removes the asset pipeline. You can also check if Rails.application.assets returns nil. Basically nothing from /assets gets compiled or served.

Possible solution: https://medium.com/alturasoluciones/how-to-set-up-rails-api-app-to-use-activeadmin-79b418df8aad

The issue is that they make the API only and afterwards add everything that is removed through the config back to the app. Also read the comments in the blogpost for further insight and implications.

Upvotes: 1

Related Questions