Skip to content

Commit

Permalink
Merge pull request #2301 from swcraig/remove-duplication-in-api-varia…
Browse files Browse the repository at this point in the history
…nts-controller

Remove duplication in API variants controller
  • Loading branch information
jhawthorn authored Oct 20, 2017
2 parents dfb77a7 + c6d38fb commit f137f97
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions api/app/controllers/spree/api/variants_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def destroy
# we render on the view so we better update it any time a node is included
# or removed from the views.
def index
@variants = scope.includes({ option_values: :option_type }, :product, :default_price, :images, { stock_items: :stock_location })
@variants = scope.includes(include_list)
.ransack(params[:q]).result

@variants = paginate(@variants)
Expand All @@ -34,7 +34,7 @@ def new
end

def show
@variant = scope.includes({ option_values: :option_type }, :option_values, :product, :default_price, :images, { stock_items: :stock_location })
@variant = scope.includes(include_list)
.find(params[:id])
respond_with(@variant)
end
Expand Down Expand Up @@ -74,6 +74,10 @@ def scope
def variant_params
params.require(:variant).permit(permitted_variant_attributes)
end

def include_list
[{ option_values: :option_type }, :product, :default_price, :images, { stock_items: :stock_location }]
end
end
end
end

0 comments on commit f137f97

Please sign in to comment.