Created
July 8, 2010 16:20
-
-
Save humanzz/468245 to your computer and use it in GitHub Desktop.
A rails helper to help you organize javascripts in your views
This file contains 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
module JavascriptsHelper | |
# This helper yeilds contents to 2 places that should be available | |
# in the application layout. One for including javascript files, | |
# the other is for including initialization codes. The layout should have | |
# something as follows: | |
# <%= yield :javascripts %> | |
# <script type="text/javascript"> | |
# $(function({ | |
# <%= yield :javascripts_ready %> | |
# })); | |
# </script> | |
# Example usage in a certain page: | |
# <% javascripts 'file1', 'file2' do %> | |
# alert('welcome here!'); | |
# <% end %> | |
def javascripts(*args, &block) | |
content_for(:javascripts) {javascript_include_tag(*args)} if args.length > 0 | |
content_for(:javascripts_ready, &block) if block_given? | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment