Added flashes to products
This commit is contained in:
parent
1a50fb5cf2
commit
6cbe661a6d
3 changed files with 29 additions and 0 deletions
|
@ -23,6 +23,7 @@ class ProductsController < ApplicationController
|
||||||
def update
|
def update
|
||||||
@product = Product.find(params[:id])
|
@product = Product.find(params[:id])
|
||||||
if @product.update_attributes(product_params)
|
if @product.update_attributes(product_params)
|
||||||
|
flash[:success] = "Succesfully updated product"
|
||||||
redirect_to action: :index
|
redirect_to action: :index
|
||||||
else
|
else
|
||||||
render 'edit'
|
render 'edit'
|
||||||
|
@ -31,6 +32,7 @@ class ProductsController < ApplicationController
|
||||||
|
|
||||||
def destroy
|
def destroy
|
||||||
Product.find(params[:id]).destroy
|
Product.find(params[:id]).destroy
|
||||||
|
flash[:success] = "Succesfully removed product"
|
||||||
redirect_to products_path
|
redirect_to products_path
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
26
app/views/application/_flash.html.erb
Normal file
26
app/views/application/_flash.html.erb
Normal file
|
@ -0,0 +1,26 @@
|
||||||
|
<div id="flash">
|
||||||
|
<% if flash[:error] %>
|
||||||
|
<div class="alert alert-danger alert-dismissable">
|
||||||
|
<button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>
|
||||||
|
<strong>Error!</strong> <%= flash[:error] %>
|
||||||
|
</div>
|
||||||
|
<% end %>
|
||||||
|
<% if flash[:success] %>
|
||||||
|
<div class="alert alert-success alert-dismissable">
|
||||||
|
<button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>
|
||||||
|
<strong>Success!</strong> <%= flash[:success] %>
|
||||||
|
</div>
|
||||||
|
<% end %>
|
||||||
|
<% if flash[:notice] %>
|
||||||
|
<div class="alert alert-info alert-dismissable">
|
||||||
|
<button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>
|
||||||
|
<strong>Notice!</strong> <%= flash[:notice] %>
|
||||||
|
</div>
|
||||||
|
<% end %>
|
||||||
|
<% if flash[:warning] %>
|
||||||
|
<div class="alert alert-warning alert-dismissable">
|
||||||
|
<button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>
|
||||||
|
<strong>Warning!</strong> <%= flash[:warning] %>
|
||||||
|
</div>
|
||||||
|
<% end %>
|
||||||
|
</div>
|
|
@ -1,4 +1,5 @@
|
||||||
<h1>All products</h1>
|
<h1>All products</h1>
|
||||||
|
<%= render partial: 'flash' %>
|
||||||
|
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-md-12">
|
<div class="col-md-12">
|
||||||
|
|
Loading…
Reference in a new issue