Rails Admin: add javascript library to custom action
Asked Answered
A

1

1

I'm building a custom action for rails admin that includes a custom view. I want to include a local copy of sparkline.js but I can't figure out a way to do this.

I tried to add the sparkline.js to the /vendor/assets/javascripts/actions/action_name directory but it is not loaded by rails admin

Is there any other way to get this file loaded

Arnuad answered 27/6, 2013 at 17:20 Comment(6)
i think this thread should help: groups.google.com/forum/#!topic/rails_admin/KgUl3gF5kTgHein
@Hein mhh I had this solution in mind but the problem is that my changes to custom/ui.js would be overwritten by the users own changes. Antoher way would be to tell the user he should require the file in his custom/ui.js but thats not the best way I think :\Arnuad
the user? what does the user have to do with this?Hein
The user who uses the plugin...Arnuad
which plugin? you did not mention any pluginHein
ah damn I thought this would be clear but ofcourse it isn't. At the end the custom action I aim to build will be a plugin/gem which can be used in multiple rails appsArnuad
I
4

I did this by putting the external library into the app/assets/javascripts/rails_admin/custom directory and adding a 'require' statement to the rails_admin ui.js file.

i.e.

// in app/assets/javascripts/rails_admin/custom/ui.js
//= require ./sparkline.js

You can do this with coffeescript too:

# in app/assets/javascripts/rails_admin/custom/ui.js.coffee
#= require ./sparkline.js
Interpose answered 1/10, 2014 at 10:56 Comment(1)
what do i do for jquery? I need to execute things after jquery loads...!Eserine

© 2022 - 2024 — McMap. All rights reserved.