I found the following worked well in my case. I added the following to config/initializers/assets.rb:
sub_folder = 'page_assets'
specific_assets_path = Rails.root.join('app', 'assets', 'javascripts', sub_folder).to_path
Dir.glob("#{specific_assets_path}/*.{js,coffee}").entries.each { |file|
asset = "#{sub_folder}/#{File.basename(file, File.extname(file))}.js"
Rails.application.config.assets.precompile += [ asset ]
}
Then I put my js and coffee files in app/assets/javascript/page_assets
e.g my_page.coffee
Now in my view I add:
<%=
javascript_include_tag 'page_assets/my_page'
%>
My view is an html.erb partial, but the same should work for a page that is defined in the my_page.rb file.
My active_admin.js just requires the active_admin base, because I don't want the active_admin asset to include all my per-page scripts:
//= require active_admin/base
The advantage of this mechanism is that I don't need to remember to add to the precompile list when I add a new per-page script - it's done automatically. ActiveAdmin won't add my page_assets scripts to the active_admin.js main asset (because I haven't got require_tree . in active_admin.js)