Один способ сделать это должно было бы записать агент Java с помощью инструментарий API . Это позволило бы Вам записывать загрузку классов JVM.
public class ClassLoadedAgent implements ClassFileTransformer {
private static ClassLoadedAgent AGENT = null;
/** Agent "main" equivalent */
public static void premain(String agentArguments,
Instrumentation instrumentation) {
AGENT = new ClassLoadedAgent();
for (Class> clazz : instrumentation.getAllLoadedClasses()) {
AGENT.add(clazz);
}
instrumentation.addTransformer(AGENT);
}
private final Map> classMap = new WeakHashMap>();
private void add(Class> clazz) {
add(clazz.getClassLoader(), clazz.getName());
}
private void add(ClassLoader loader, String className) {
synchronized (classMap) {
System.out.println("loaded: " + className);
Set set = classMap.get(loader);
if (set == null) {
set = new HashSet();
classMap.put(loader, set);
}
set.add(className);
}
}
private boolean isLoaded(String className, ClassLoader loader) {
synchronized (classMap) {
Set set = classMap.get(loader);
if (set == null) {
return false;
}
return set.contains(className);
}
}
@Override
public byte[] transform(ClassLoader loader, String className,
Class> classBeingRedefined, ProtectionDomain protectionDomain,
byte[] classfileBuffer) throws IllegalClassFormatException {
add(loader, className);
return classfileBuffer;
}
public static boolean isClassLoaded(String className, ClassLoader loader) {
if (AGENT == null) {
throw new IllegalStateException("Agent not initialized");
}
if (loader == null || className == null) {
throw new IllegalArgumentException();
}
while (loader != null) {
if (AGENT.isLoaded(className, loader)) {
return true;
}
loader = loader.getParent();
}
return false;
}
}
META-INF/MANIFEST.MF:
Manifest-Version: 1.0
Premain-Class: myinstrument.ClassLoadedAgent
оборотная сторона - то, что необходимо загрузить агент при запуске JVM:
java -javaagent:myagent.jar ....etcetera
В вашем контроллере динамически выбирать, использовать ли макет на основе request.xhr?
.
Например:
class SomeController < ApplicationController
layout :get_layout
protected
def get_layout
request.xhr? ? nil : 'normal_layout'
end
end
В методе контроллера просто сделайте следующее:
respond_to do |format|
format.js if request.xhr?
format.html { redirect_to :action => "index"}
end
If you're using a new version of rails you can just append .js onto the path and it will infer that the request is a JavaScript call