Skip to content

Instantly share code, notes, and snippets.

@edymerchk
Last active December 2, 2015 13:15
Show Gist options
  • Save edymerchk/90d9980a0d0a9c0886f8 to your computer and use it in GitHub Desktop.
Save edymerchk/90d9980a0d0a9c0886f8 to your computer and use it in GitHub Desktop.
active_admin custom js page scope
# app/assets/javascripts/active_admin.js.coffee
#= require active_admin/base
ActiveAdmin = {
dashboard: {},
user: {}
}
ActiveAdmin.dashboard.index = () ->
console.log 'Hello'
$(() ->
controller = $('body').data('controller')
action = $('body').data('action')
ActiveAdmin[controller][action]() if ActiveAdmin[controller][action]?
)
# app/admin/layout_hacks.rb
module ActiveAdmin::Views::Pages::BaseExtension
def add_classes_to_body
super
@body.set_attribute "data-controller", params[:controller].gsub(/^admin\//, '')
@body.set_attribute "data-action", params[:action]
end
end
class ActiveAdmin::Views::Pages::Base
# mixes in the module directly below the class
prepend ActiveAdmin::Views::Pages::BaseExtension
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment