views:

39

answers:

3

Hi!

I want use jquery in my project. I know the javascript_include_tag calls the jqeury plugins, but the tag how works in ruby?

example

<%= javascript_include_tag 'jquery.ui.potato.menu.js' %>
<%= javascript_include_tag 'http://ajax.googleapis.com/ajax/libs/jquery/1.3.1/jquery.min.js' %>

<script type="text/javascript">
(function($) {
        $(document).ready(function(){
                $('#menu1').ptMenu();
        });
})(jQuery);
</script>

This is not workink in RoR

+2  A: 

Put the

<%= javascript_include_tag 'http://ajax.googleapis.com/ajax/libs/jquery/1.3.1/jquery.min.js' %>

before any jquery plugins. (i.e. the potato thing.)

DanSingerman
+1  A: 

You need to reverse your script tags, like this:

<%= javascript_include_tag 'http://ajax.googleapis.com/ajax/libs/jquery/1.3.1/jquery.min.js' %>
<%= javascript_include_tag 'jquery.ui.potato.menu.js' %>

jQuery needs to be loaded before anything that depends on jQuery tries to run, e.g. plugins.

Also consider upgrading if you're just getting started. If the plugin you're using support it, the latest (as of the time of this answer) is 1.4.2.

Nick Craver
A: 

What doesn't work? if the first file in the order needs jQuery in order to work (usually does) then you should load it only after jquery loads, meaning change the order of the files.

another thing, check with firebug if the files are loading correctly and there's no 404 error or something like that

Avi Tzurel