我的Flash消息在我不希望它出现的页面上停留有问题。
我正在使用带有turbo链接的Rails 4。
虽然我非常喜欢turbo链接,但我认为这可能是问题所在。
在我的rails控制器中,我按照以下方式设置了所需的闪光灯:
def show
if item.status == "In Progress" || item.status == "draft"
flash[:alert] = "Please remember: the status of this text is draft. You have been granted access through the generosity of the editor. Please use the comments to help make suggestions or corrections."
end
end
但是,当我点击链接并且turbo链接响应性地加载新页面时,闪存再次出现。
关于如何在继续使用turbolinks的同时防止这种情况的任何想法
答案 0 :(得分:1)
您可以在应用程序控制器中清除before_action中的flash消息 在application_controller.rb
中before_action :clear_flash
def clear_flash
flash.discard
end
或者只需将代码更改为:
def show
if item.status == "In Progress" || item.status == "draft"
flash.now[:alert] = "Please remember: the status of this text is draft. You have been granted access through the generosity of the editor. Please use the comments to help make suggestions or corrections."
end
end