Last active
December 2, 2015 13:15
-
-
Save edymerchk/90d9980a0d0a9c0886f8 to your computer and use it in GitHub Desktop.
active_admin custom js page scope
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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]? | |
) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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