0

或者也许有人知道一个更好的 ajax 闪光通知系统???(编辑)

我正在努力让 grittier(https://github.com/RobinBrouwer/gritter)通知与 ajax 一起工作,这就是我到目前为止所得到的:

应用程序.html.erb

<%= gflash %>
<%= gflash :js => true %>

request_fr.rb

  def request_fr
  respond_to do |format|
    format.js{}
        gflash :now, :notice => "TEST gflash :now, :notice =>"
        gflash :success => "TEST2 gflash :success => "
      end
  end

request_fr.js.erb(在这里尝试了很多东西,似乎没有任何效果)

<%= js add_gritter(flash[:notice].to_s, :image => :notice, :title => "Pay attention!", :sticky => true) %>
<%= gflash :js => true %>
 <% if flash.now[:notice] %>
    $.gritter.add({
      title: '--',
      text: '<%= escape_javascript(flash.now[:notice].to_s) %>'
    });
  <% end %>

错误之一不再得到这个,.to_s 修复了它。但仍然没有收到消息

Rendered friendships/request_fr.js.erb within layouts/application (2.7ms)
Completed 500 Internal Server Error in 97ms

NoMethodError - undefined method `gsub' for ["TEST gflash :now, :notice =>"]:Array:
  actionpack (3.2.13) lib/action_view/helpers/javascript_helper.rb:30:in `escape_javascript'
  gritter (1.1.0) lib/gritter/helpers.rb:19:in `add_gritter'
  app/views/friendships/request_fr.js.erb:1:in `_app_views_friendships_request_fr_js_erb__426745901290841
9434_2281294440'

不太清楚如何设置,尝试了很多不同的方法;/

4

1 回答 1

0

这对我有用:在你的 js 文件中

     <%= add_gritter("Notice", :image => :success, :title => "Notice" ) %>
于 2015-06-30T13:41:03.727 回答