views:

69

answers:

2

Tried doing http://davidwparker.com/2008/09/17/site-wide-announcements-in-rails-using-jquery-jgrowl/

Am really bad with JS. Think I am messing up on the last part where it says "This code goes in your application.js file (somewhere in $(function){ //here })"

Am I not suppose to do a link_to_function and create a function with this code that references that link?

Really lost on this one.

Updated -

application.js looks like

$(document).ready(function() {
    $.jGrowl.defaults.closer = true;
      $("#announcements_box").css("display", "none");
      $("#announcements_box .announcement").each(function(){
        $jQuery.jGrowl(this.textContent,{ sticky:true, close:function(e,m,o){hide_announcements();} });
      });

 });

function hide_announcements(){
    $.get(
      '/hide_announcements'
    );

    $("#announcements_box").fadeOut();
    return false;
  }

And my application.html.erb has

<% unless current_announcements.empty? %>
<div id="announcements_box">
<% for announcement in current_announcements %>
    <div id="announcement_<%= announcement.id.to_s %>"  class="jGrowl">
    <%= announcement.message %>
    <%= link_to "Hide Annoucements", hide_announcements_path, :id => 'hideAnn'%>
    </div>
<% end %>
</div>
<% end %>
A: 

I'm not sure what $(function){ //here } notation means, that should give you error in the browser, but I think he just wants to execute code after page is loaded:

$(document).ready(function() {
    // here
}
Nikita Rybak
that's what I thought too, but it actually hides it on document load (unless the "display", "none" is backwards).
pcasa
A: 

And the culprit was I only entered a div ID when I needed to have a div ID and class.

pcasa