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
- #initialize_vars ⇒ Object
- #new ⇒ Object
-
#permitted_params ⇒ Object
so now two additional keys get added one -> embedded_document_path two -> embedded_document.
- #show ⇒ Object
- #update ⇒ Object
Instance Method Details
#create ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 |
# File 'app/controllers/auth/concerns/shopping/product_controller_concern.rb', line 21 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}) #puts "this is the auth shopping product" #puts @auth_shopping_product.embedded_document #puts @auth_shopping_product.embedded_document_path #@auth_shopping_product.send("#{@auth_shopping_product.embedded_document_path}=",@auth_shopping_product.embedded_document) if (@auth_shopping_product.embedded_document && @auth_shopping_product.embedded_document_path) @auth_shopping_product.save respond_with @auth_shopping_product end |
#destroy ⇒ Object
81 82 83 84 85 |
# File 'app/controllers/auth/concerns/shopping/product_controller_concern.rb', line 81 def destroy check_for_destroy(@auth_shopping_product) @auth_shopping_product.delete respond_with @auth_shopping_product end |
#edit ⇒ Object
91 92 93 |
# File 'app/controllers/auth/concerns/shopping/product_controller_concern.rb', line 91 def edit end |
#index ⇒ Object
70 71 72 73 |
# File 'app/controllers/auth/concerns/shopping/product_controller_concern.rb', line 70 def index instantiate_shopping_classes @auth_shopping_products = @auth_shopping_product_class.all end |
#initialize_vars ⇒ Object
11 12 13 14 15 16 17 |
# 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 "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
87 88 89 |
# File 'app/controllers/auth/concerns/shopping/product_controller_concern.rb', line 87 def new end |
#permitted_params ⇒ Object
so now two additional keys get added one -> embedded_document_path two -> embedded_document.
98 99 100 101 102 103 |
# File 'app/controllers/auth/concerns/shopping/product_controller_concern.rb', line 98 def permitted_params ## we just keep the embedded_document_path ## i need to change the controllers back to product ## and i need to pr = params.permit({:product => [:name,:price]}) end |
#show ⇒ Object
75 76 77 78 79 |
# File 'app/controllers/auth/concerns/shopping/product_controller_concern.rb', line 75 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
33 34 35 36 37 38 39 40 41 42 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 |
# File 'app/controllers/auth/concerns/shopping/product_controller_concern.rb', line 33 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) ## assigns the embedded document to the provided path. =begin if @auth_shopping_product.embedded_document_path curr_element = nil total_els = @auth_shopping_product.embedded_document_path.split(".").size @auth_shopping_product.embedded_document_path.split(".").each_with_index {|path,key| if key == (total_els - 1) if curr_element.nil? @auth_shopping_product.send(path + "=",@auth_shopping_product.embedded_document) else curr_element.send(path + "=",@auth_shopping_product.embedded_document) if (path =~ /[a-z]+/) curr_element.send(:[]=,path.to_i,@auth_shopping_product.embedded_document) if (path =~ /\d+/) end else if curr_element.nil? curr_element = @auth_shopping_product.send(path) else curr_element = curr_element.send(path) if (path =~ /[a-z]+/) curr_element = curr_element[path.to_i] if path=~/\d+/ end end } end =end ## prune nil elements. ## at all levels. @auth_shopping_product.save respond_with @auth_shopping_product end |