フラッシュ メッセージを表示するために、application_helper にヘルパーを作成しました。このコードは、Stack Overflow で見つけたコードに基づいており、次のように変更しています。
def show_flash
flash_names = [:notice, :warning, :message, :error]
flash_html = ''
for name in flash_names
if flash[name]
flash_html = flash_html + "<div class=\"#{name}\">#{flash[name]}</div>"
end
flash[name] = nil;
end
flash_html
end
これを実行すると、ページでフラッシュ メッセージを取得する代わりに、show_flash ヘルパーが生成した実際の html をすべてのマークアップを含めて取得します。
<div class="notice">Item was successfully updated.</div>
私の application.html.erb ファイルは次のようになります。
<!DOCTYPE html>
<html>
<head>
<title>My Application</title>
<%= stylesheet_link_tag "application" %>
<%= javascript_include_tag "application" %>
<%= csrf_meta_tags %>
</head>
<body>
<h1 align="center">Welcome to XYZ Application</c></h1>
<%= show_flash %>
<%= yield %>
</body>
</html>
私は何を間違っていますか?