diff options
Diffstat (limited to 'app/controllers/api')
-rw-r--r-- | app/controllers/api/products_controller.rb | 16 |
1 files changed, 9 insertions, 7 deletions
diff --git a/app/controllers/api/products_controller.rb b/app/controllers/api/products_controller.rb index ec82af6..0c3a30b 100644 --- a/app/controllers/api/products_controller.rb +++ b/app/controllers/api/products_controller.rb @@ -4,9 +4,7 @@ module Api # ProductsController class ProductsController < MasterController def show - @product = Product.find_by(public_id: params[:id]) - - render json: not_found_error_message, status: :not_found and return if @product.nil? + render json: not_found_error_message, status: :not_found and return if product.nil? render json: serialized_object.serializable_hash, status: :ok end @@ -48,11 +46,15 @@ module Api private + def product + @product ||= Product.joins(:company) + .select('products.*', 'companies.name as company_name', + 'companies.short_name as company_short_name') + .find_by(public_id: params[:id]) + end + def serialized_object - Serializers::ProductSerializer.new( - @product.joins(:company) - .select('products.*', 'companies.name as company_name','companies.short_name as company_short_name') - ) + Serializers::ProductSerializer.new(product) end def serialized_collection |