Skip to content

Instantly share code, notes, and snippets.

@gbmoretti
Created February 24, 2014 21:51
Show Gist options
  • Save gbmoretti/9197932 to your computer and use it in GitHub Desktop.
Save gbmoretti/9197932 to your computer and use it in GitHub Desktop.
Pamela
<!-- layouts/application.html.erb -->
<!DOCTYPE html>
<html>
<head>
<%= stylesheet_link_tag "application" %>
</head>
<body data-controller="<%= controller_name %>" data-view="<%= action_name %>">
<%= yield %>
<!-- Scripts Js -->
<%= javascript_include_tag "application" %>
</body>
</html>
// app/assets/javascript/application/app/posts/index.js
window.defineAction('posts','index',function() {
console.log('estou em posts#index');
});
window.defineAction = function(controller,view,fn) {
window[controller] = window[controller] || {};
if(window[controller][view] !== undefined) {
new Error(controller+'#'+view + ' function already defined.');
}else {
window[controller][view] = fn;
}
};
window.onload = function() {
//get controller and action from body data-attribute
var body = window.document.getElementsByTagName('body')[0];
var controller = body.dataset.controller;
var action = body.dataset.view;
if(window[controller][action] !== undefined) {
window[controller][action]();
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment