I am trying to display flash message while handling errors from ActionController with the following code:
class ActionController < ApplicationController
def action
begin
@results = ApiHelper.helper(paremeter)
rescue StandardError => e
flash[:danger] = "show some error messages"
end
render "something"
end
end
I also define the flash message with the following code in views/layouts/applications.html.erb
<body>
<%= render 'layouts/header' %>
<div class="container">
<% flash.each do |message_type, message| %>
<div class="alert alert-<%= message_type %>"><%= message %></div>
<% end %>
<%= yield %>
<%= render 'layouts/footer' %>
<%= debug(params) if Rails.env.development? %>
</div>
</body>
Error handling works fine, but flash messages not being displayed.
Could you move
flashoutsidebegin...rescueblock to make sure working? I have just tried and everything is fine