Created
September 30, 2015 17:33
-
-
Save stujo/a668e9254cef6c0d53b8 to your computer and use it in GitHub Desktop.
Page Specific Document Ready JavaScript in Rails with jQuery
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
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="utf-8"> | |
<title>PizzaShack</title> | |
<%= stylesheet_link_tag 'application', media: 'all' %> | |
<%= javascript_include_tag 'application' %> | |
<%= csrf_meta_tags %> | |
</head> | |
<body> | |
<div class="container"> | |
<%= yield %> | |
</div> | |
</body> | |
<script> | |
// THIS IS THE IMPORTANT PART | |
var event_name = 'pizza:<%= controller_name %>_<%= action_name %>'; | |
$.event.trigger({ type: event_name}); | |
</script> | |
</html> |
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
$(document).on("pizza:pizzas_index", function(){ | |
alert('Hello on the Pizzas Page'); | |
}) |
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
$(document).on("pizza:welcome_index", function(){ | |
alert('Hello on the Welcome Index Page'); | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment