Reputation: 47
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!
Upvotes: 0
Views: 1888
Reputation: 8980
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.
Upvotes: 5
Reputation: 176552
"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.
Upvotes: 0