Ruby on rails 未在rails中显示Flash消息
我在尝试使用flash消息flash[:注意]时遇到一些问题。flash消息未显示其消息 这是我的部分表单视图Ruby on rails 未在rails中显示Flash消息,ruby-on-rails,flash-message,Ruby On Rails,Flash Message,我在尝试使用flash消息flash[:注意]时遇到一些问题。flash消息未显示其消息 这是我的部分表单视图 <%= form_tag bulk_push_api_v1_notifications_path do |f| %> <fieldset class="inputs"> <legend> <span>Details</span> </legend> <% if
<%= 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>
flash提供了一种在操作之间传递临时原语类型String、Array、Hash的方法。但您正试图将flash通知作为url_重定向参数发送。 申报
flash[:notice] = "some msg"
在重定向之前
尝试以下代码以显示flash消息:
控制器
app/views/layouts/application.html.erb
还是不行,先生,我已经按照你的建议修改了密码。非常感谢,先生,这真的很有帮助me@MuhammadRahmatullah如果我的答案对你有效,请投我的票。谢谢,先生,但是目前我在你的答案达到每日投票限制时出错了;16小时后再投票。@Muhammaddahmatullah Ok Np
flash[:notice] = "some msg"
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
<% 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>