This will sound like a stupid question for most but I'm really having problems with adding JavaScript files (such as jquery) to my application.html.erb, if i have the jquery first then the rails JavaScript doesn't work correctly. whats the best way to include all JavaScript files to the application.html.erb from my JavaScript folder?
Edit: how can i have Jquery and Prototype run side by said in my rails 3 application? what should my application.html.erb code look like?
If you want to use jQuery and Prototype side-by-side, you should order your javascript include statements as follows:
<%= javascript_include_tag :defaults, "jquery.min", "jquery-ui.min" %>
<script type="text/javascript">
jQuery.noConflict();
</script>
Note: After doing this, you will not be able to access any jQuery methods using $(...)
. Instead, you'll need to use jQuery(...)
However, if you don't need Prototype, delete your prototype.js
file and install the proper jQuery-specific rails.js
file (the one that Rails uses by default is Prototype-specific). See https://github.com/rails/jquery-ujs for instructions.