Commit 6e7cea70 by Nguyen Quoc Kien

Review code: Move find_product() to application_controller

parent 5fca702f
...@@ -43,10 +43,6 @@ class Admin::ProductsController < ApplicationController ...@@ -43,10 +43,6 @@ class Admin::ProductsController < ApplicationController
private private
def find_product
@product = Product.find(params[:id])
end
def product_params def product_params
params.require(:product).permit(:category_id, :name, :price, :image, :description) params.require(:product).permit(:category_id, :name, :price, :image, :description)
end end
......
...@@ -41,4 +41,13 @@ class ApplicationController < ActionController::Base ...@@ -41,4 +41,13 @@ class ApplicationController < ActionController::Base
def is_number? string def is_number? string
true if Float(string) rescue false true if Float(string) rescue false
end end
def find_product
if params[:id].to_i > (Product.count + 1)
redirect_to error_path
else
@product = Product.find(params[:id])
end
end
end end
...@@ -11,14 +11,4 @@ class ProductsController < ApplicationController ...@@ -11,14 +11,4 @@ class ProductsController < ApplicationController
@categories = Category.all @categories = Category.all
end end
private
def find_product
if params[:id].to_i > (Product.count + 1)
redirect_to error_path
else
@product = Product.find(params[:id])
end
end
end end
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment