0

So I'm trying to get some basic jQuery code with Rails working, but it doesn't seem to be working out. I've looked around and it seems like I'm following all of the directions correctly and have tried it in multiple browsers with no avail. Essentially, I'm just trying to slide up a div on document ready, but it just stays there :(

<%= javascript_include_tag ['jquery-1.3.2', 'application'], :cache => true %>
<%= stylesheet_link_tag 'stylesheet' %>
<script type="text/javascript">
$(document).ready(function () {
    $('#login').hide("slide", { direction: "up"}, 5000);
});
</script>
<div id="container">
    <div id="left_nav">
        <p>Core Functions Will Go Here</p>
    </div>
    <div id="headertop"></div>
    <div id="logoheader">
        <%= link_to image_tag("vitaallogo.png"), root_path  %>      
    </div>
    <div id="user_nav">
        <% if current_user%>
            <%= link_to "Logout", logout_path %>
        <% else %>
            <%= link_to "Register", {:controller => 'user', :action => 'new'}%> |
            <%= link_to "Login", login_path %>
        <% end %>
    </div><br />
    <%= yield %>    
</div>
<div id="login">
 <strong>nonononononononono</strong>
</div>

Any information anyone can provide would be appreciated!

2 Answers 2

5

The issue may be that Rails is using prototype out of the box. There may be a conflict between the two libraries (they both use the $ sign).

Take a look at this: http://docs.jquery.com/Using_jQuery_with_Other_Libraries

Then, you should try that:

  <script type="text/javascript">
    $j = jQuery.noConflict();

    $j(document).ready(function () {
       $j('#login').hide("slide", { direction: "up"}, 5000);
    });
  </script>

Then if you still want to use prototype, you can still use it using the $ sign.

Sign up to request clarification or add additional context in comments.

2 Comments

You could also not use prototype and go with jRails ( github.com/aaronchi/jrails )
See the section 'Referencing Magic - Shortcuts for jQuery' (docs.jquery.com/Using_jQuery_with_Other_Libraries) for a way to keep $'s meaning for both jQuery and Prototype so you can use all those cool jQuery libraries out there.
0

"Not working" is a bit vague. Makes sure the files are correctly included with the javascript_include_tag. AFAIK, when you put a dot in the filename, the helper doesn't automatically append the .js extension. You need to include the full filename.

<%= javascript_include_tag 'jquery-1.3.2.js', 'application', :cache => true %>

Additionally, I would suggest to use jRails.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.