我在Rails 5应用程序中使用磨刀通知,无法找到删除通知弹出的默认标题的方法。我在下面加了一个磨刀:
<%= js add_gritter(flash[:notice], title: 'I dont need you', sticky: false) %>试过:
<%= js add_gritter(flash[:notice], title: false, sticky: false) %>
<%= js add_gritter(flash[:notice], title: nil, sticky: false) %>
<%= js add_gritter(flash[:notice], title: '', sticky: false) %>
<%= js add_gritter(flash[:notice], title: ' ', sticky: false) %>弹出窗口中仍然会出现默认标题--“通知”。试图搜索整个应用程序的项目“通知”或“磨磨机”,但没有发现任何相关。
怎么摆脱它?
发布于 2017-10-13 15:35:33
gem中的add_gritter方法将options[:title]设置为"Notification“(如果options[:title].blank?返回true )。
“脏”选项是使用选项散列(而不是*args )再次定义它,如果将标题作为选项参数传递,则呈现标题,如下所示:
def add_gritter(text, options={})
if %w(success warning error notice progress).include?(options[:image].to_s)
options[:image] = image_path("#{options[:image]}#{options[:image].to_s == 'progress' ? '.gif' : '.png'}")
end
notification = Array.new
notification.push("jQuery(function(){") if options[:nodom_wrap].blank?
notification.push("jQuery.gritter.add({")
notification.push("image:'#{options[:image]}',") if options[:image].present?
notification.push("sticky:#{options[:sticky]},") if options[:sticky].present?
notification.push("time:#{options[:time]},") if options[:time].present?
notification.push("class_name:'#{options[:class_name]}',") if options[:class_name].present?
notification.push("before_open:function(e){#{options[:before_open]}},") if options[:before_open].present?
notification.push("after_open:function(e){#{options[:after_open]}},") if options[:after_open].present?
notification.push("before_close:function(e){#{options[:before_close]}},") if options[:before_close].present?
notification.push("after_close:function(e){#{options[:after_close]}},") if options[:after_close].present?
notification.push("on_click:function(e){#{options[:on_click]}},") if options[:on_click].present?
notification.push("title:'#{escape_javascript(options[:title])}',") if options[:title].blank? # Here
notification.push("text:'#{escape_javascript(text)}'")
notification.push("});")
notification.push("});") if options[:nodom_wrap].blank?
text.present? ? notification.join.html_safe : nil
end但是gritter.js文件有一个if来检查title是否有任何内容,所以您必须处理自己的内容并编辑它,只需检查文本,例如:
//We might have some issues if we don't have a title or text!
if (!params.text) {
throw 'You need to fill out the text parameter.';
}发布于 2017-10-13 14:54:43
听起来不是最好的方法,但有效。如果有任何其他解决方案-请随意:)
.gritter-title {
display: none;
}编辑:
因为我使用SCSS,所以这样做更好:
<%= js add_gritter(flash[:notice], sticky: false, :on_click => remove_gritter, :time => 100000, class_name: 'no-title') %>
.no-title {
.gritter-title {
display: none;
}
}https://stackoverflow.com/questions/46732245
复制相似问题