Flash消息未显示在rails中

时间:2017-11-28 03:10:41

标签: ruby-on-rails flash-message

尝试使用Flash消息 $('#select_all').live('click', function () { if(this.checked) { // i need to fetch all id's from all td's // 100,101 } }); 时遇到了一些问题。 flash消息未显示消息

这是我的部分表单视图

flash[:notice]

它将从控制器

触发此方法
<%= form_tag bulk_push_api_v1_notifications_path do |f| %>
<fieldset class="inputs">
    <legend>
        <span>Details</span>
    </legend>
        <% if flash[:notice].present? %>
          <p class='flash-notice'><%= flash[:notice] %></p>
        <% elsif flash[:error].present? %>
          <p class='flash-error'><%= flash[:error] %></p>
        <% end %>
    <ol>
        <li class="file input required" id="play_media_input">
             <%= label_tag(:message, "Message : ") %>
             <%= text_area_tag :message,  nil, :required => true %>
            <p class="inline-hints">Only text can be sent</p>
        </li>
    </ol>
</fieldset>
<fieldset class="actions">
    <ol>
        <li class="action input_action " id="play_submit_action">
            <%= submit_tag("Send Notification") %>
        </li>
    </ol>
</fieldset>

1 个答案:

答案 0 :(得分:3)

尝试使用以下代码显示flash条消息:

控制器

def bulk_push
  begin
    User.send_bulk_notifications(params[:message])
    redirect_to admin_notification_path, notice: "Insufficient rights!"
  rescue
    redirect_to admin_notification_path, alert: "Error"
  end

end

的应用程序/视图/布局/ application.html.erb

<% if notice %>
  <p class="alert alert-success"><%= notice %></p>
<% end %>
<% if alert %>
  <p class="alert alert-danger"><%= alert %></p>
<% end %>

<style type="text/css">
  .alert-success{
    color: green;
  }
  .alert-danger{
    color: red;
  }
</style>
相关问题