From 6cbe661a6dc4b04d570d52ff00416c81bebfc465 Mon Sep 17 00:00:00 2001 From: Tom Naessens Date: Tue, 9 Dec 2014 14:42:50 +0100 Subject: [PATCH] Added flashes to products --- app/controllers/products_controller.rb | 2 ++ app/views/application/_flash.html.erb | 26 ++++++++++++++++++++++++++ app/views/products/index.html.erb | 1 + 3 files changed, 29 insertions(+) create mode 100644 app/views/application/_flash.html.erb diff --git a/app/controllers/products_controller.rb b/app/controllers/products_controller.rb index 6d71fc3..65b79e7 100644 --- a/app/controllers/products_controller.rb +++ b/app/controllers/products_controller.rb @@ -23,6 +23,7 @@ class ProductsController < ApplicationController def update @product = Product.find(params[:id]) if @product.update_attributes(product_params) + flash[:success] = "Succesfully updated product" redirect_to action: :index else render 'edit' @@ -31,6 +32,7 @@ class ProductsController < ApplicationController def destroy Product.find(params[:id]).destroy + flash[:success] = "Succesfully removed product" redirect_to products_path end diff --git a/app/views/application/_flash.html.erb b/app/views/application/_flash.html.erb new file mode 100644 index 0000000..312b24d --- /dev/null +++ b/app/views/application/_flash.html.erb @@ -0,0 +1,26 @@ +
+ <% if flash[:error] %> +
+ + Error! <%= flash[:error] %> +
+ <% end %> + <% if flash[:success] %> +
+ + Success! <%= flash[:success] %> +
+ <% end %> + <% if flash[:notice] %> +
+ + Notice! <%= flash[:notice] %> +
+ <% end %> + <% if flash[:warning] %> +
+ + Warning! <%= flash[:warning] %> +
+ <% end %> +
diff --git a/app/views/products/index.html.erb b/app/views/products/index.html.erb index e0ad80b..5c8fbe0 100644 --- a/app/views/products/index.html.erb +++ b/app/views/products/index.html.erb @@ -1,4 +1,5 @@

All products

+<%= render partial: 'flash' %>