Rails Flash.现在不行了



我有一个视图,从中我向控制器发出ajax请求,在动作成功完成后,我初始化flash.now[:notice]。但是在控件回到视图之后。我没有看到闪光信息。

flash.now[:notice] = "Request Completed successfully" if @meetings.any?

重定向时使用

flash[:notice] = "This message value is available in next request-response cycle"

渲染时使用

flash.now[:notice] = "Message is available in same request-response cycle"

Info from here

你会闪光吗?现在在你调用渲染之前?

如果您使用form_with,则需要使用local: true

<%= form_with @user, local: true do |f| %>
  <%= f.label :name %>
  <%= f.text_field :name %>
  <%= f.submit %>
<% end %>

控制器中的代码:

flash[:success] = "All good!"
format.html { redirect_to some_path}

并在视图中使用关闭按钮:

<% flash.each do |key, value| %>
 <%= content_tag(:div, class: "alert alert-#{key} alert-dismissable") do %>
  <%= value %>
  <button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button>   
 <% end %> 
<% end %>

检查是否有类似

的内容
<% flash.each do |key, value| %>
    <div class="flash <%= key %>"><%= value %></div>
<% end %>

在application.html.erb文件中:如果你没有,你必须添加它,因为这是通知将显示的地方。

相关内容

最新更新