Implementing Flash Messages to your Website

<div class=’container’>
<% flash.each do |name, message| %>
<div class=”alert alert-<%= name %> alert-dismissible” role=”alert”>
<button type=”button” class=”close” data-dismiss=”alert” aria-label=”Close”><span aria-hidden=”true”>&times;</span></button>
<%= message %>
</div>
<% end %>
</div>
def create
product = Product.new(
name: params[“name”],
price: params[“price”],
description: params[“description”],
supplier_id: rand(1..2)
)
product.save
image = Image.new(
url: params[“url”],
product_id: product.id
)
image.save

flash[:success] = “Product Successfully Added!”
redirect_to ‘/products’
end

--

--

Love podcasts or audiobooks? Learn on the go with our new app.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store