Module: Auth::Concerns::Shopping::ProductControllerConcern
- Extended by:
- ActiveSupport::Concern
- Included in:
- Shopping::ProductsController
- Defined in:
- app/controllers/auth/concerns/shopping/product_controller_concern.rb
Instance Method Summary collapse
- #create ⇒ Object
- #destroy ⇒ Object
- #edit ⇒ Object
-
#index ⇒ Object
index can accept product bundle as a parameter.
- #initialize_vars ⇒ Object
- #new ⇒ Object
- #permitted_params ⇒ Object
- #show ⇒ Object
- #update ⇒ Object
Instance Method Details
#create ⇒ Object
22 23 24 25 26 27 |
# File 'app/controllers/auth/concerns/shopping/product_controller_concern.rb', line 22 def create check_for_create(@auth_shopping_product) @auth_shopping_product = add_owner_and_signed_in_resource(@auth_shopping_product,{:owner_is_current_resource => true}) @auth_shopping_product.save respond_with @auth_shopping_product end |
#destroy ⇒ Object
94 95 96 97 98 |
# File 'app/controllers/auth/concerns/shopping/product_controller_concern.rb', line 94 def destroy check_for_destroy(@auth_shopping_product) @auth_shopping_product.delete respond_with @auth_shopping_product end |
#edit ⇒ Object
104 105 106 |
# File 'app/controllers/auth/concerns/shopping/product_controller_concern.rb', line 104 def edit end |
#index ⇒ Object
index can accept product bundle as a parameter. like only show the bundles. if we want to show that then? okay so let us add that bundle parameter.
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'app/controllers/auth/concerns/shopping/product_controller_concern.rb', line 43 def index instantiate_shopping_classes if params[:query_string] if params[:autocomplete_bundle_name] ## in this case, the autocomplete query has to be done. args = {:query_string => params[:query_string]} query = Auth::Search::Main.es_six_finalize_search_query_clause(args) Auth.configuration.product_class.constantize.bundle_autocomplete_aggregation(query) @auth_shopping_results = Auth.configuration.product_class.constantize.es.search(query,{:wrapper => :load}).results end elsif params[:group_by_bundles] results = Auth.configuration.product_class.constantize.collection.aggregate([ { "$match" => { "bundle_name" => { "$exists" => true } } }, { "$group" => { "_id" => "$bundle_name", "products" => { "$push" => "$$ROOT" } } } ]) ## we need them keyed by the bundle name. @products_grouped_by_bundle = {} @auth_shopping_products = [] results.each do |result| bundle_name = result["_id"] products = result["products"].map{|c| c = Auth.configuration.product_class.constantize.new(c)} @products_grouped_by_bundle[bundle_name] = products end else @auth_shopping_products = @auth_shopping_product_class.all end end |
#initialize_vars ⇒ Object
11 12 13 14 15 16 17 18 19 |
# File 'app/controllers/auth/concerns/shopping/product_controller_concern.rb', line 11 def initialize_vars #puts "came to initialize vars" instantiate_shopping_classes @auth_shopping_product_params = permitted_params.fetch(:product,{}) #puts "product params:" #puts @auth_shopping_product_params.to_s #puts "current signed in resource: #{current_signed_in_resource}" @auth_shopping_product = params[:id] ? @auth_shopping_product_class.find_self(params[:id],current_signed_in_resource) : @auth_shopping_product_class.new(@auth_shopping_product_params) end |
#new ⇒ Object
100 101 102 |
# File 'app/controllers/auth/concerns/shopping/product_controller_concern.rb', line 100 def new end |
#permitted_params ⇒ Object
109 110 111 112 |
# File 'app/controllers/auth/concerns/shopping/product_controller_concern.rb', line 109 def permitted_params = [:name,:price,:bundle_name,:create_from_product_id] + Auth::Shopping::BarCode.allow_params params.permit({:product => },:id) end |
#show ⇒ Object
87 88 89 90 91 92 |
# File 'app/controllers/auth/concerns/shopping/product_controller_concern.rb', line 87 def show instantiate_shopping_classes @auth_shopping_product = @auth_shopping_product_class.find(params[:id]) ## will render show.json.erb if its a json request. end |
#update ⇒ Object
29 30 31 32 33 34 35 36 37 |
# File 'app/controllers/auth/concerns/shopping/product_controller_concern.rb', line 29 def update check_for_update(@auth_shopping_product) @auth_shopping_product = add_owner_and_signed_in_resource(@auth_shopping_product,{:owner_is_current_resource => true}) @auth_shopping_product.assign_attributes(@auth_shopping_product_params) @auth_shopping_product.save puts @auth_shopping_product.errors. respond_with @auth_shopping_product end |