Module: Auth::Concerns::Work::InstructionControllerConcern
- Extended by:
- ActiveSupport::Concern
- Included in:
- Work::InstructionsController
- Defined in:
- app/controllers/auth/concerns/work/instruction_controller_concern.rb
Instance Method Summary collapse
- #create ⇒ Object
- #destroy ⇒ Object
- #edit ⇒ Object
- #get_index ⇒ Object
- #index ⇒ Object
- #initialize_vars ⇒ Object
- #new ⇒ Object
-
#permitted_params ⇒ Object
okay so how to port this to the pathofast side ? we can just package the gem and see how it fares.
- #show ⇒ Object
- #update ⇒ Object
Instance Method Details
#create ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'app/controllers/auth/concerns/work/instruction_controller_concern.rb', line 47 def create check_for_create(@auth_work_instruction) @auth_shopping_product.instructions << @auth_work_instruction @auth_shopping_product.save respond_to do |format| format.json do render json: @auth_work_instruction.to_json end format.html do render "show" end end end |
#destroy ⇒ Object
87 88 89 90 91 92 |
# File 'app/controllers/auth/concerns/work/instruction_controller_concern.rb', line 87 def destroy check_for_destroy(@auth_work_instruction) @auth_shopping_product.delete_at(get_index) @auth_shopping_product.save respond_with @auth_work_instruction end |
#edit ⇒ Object
98 99 100 |
# File 'app/controllers/auth/concerns/work/instruction_controller_concern.rb', line 98 def edit end |
#get_index ⇒ Object
37 38 39 40 41 42 43 44 |
# File 'app/controllers/auth/concerns/work/instruction_controller_concern.rb', line 37 def get_index index = 0 @auth_shopping_product.instructions.each do |ins| break if ins.id.to_s == @auth_work_instruction.id.to_s index+=1 end index end |
#index ⇒ Object
76 77 78 |
# File 'app/controllers/auth/concerns/work/instruction_controller_concern.rb', line 76 def index end |
#initialize_vars ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'app/controllers/auth/concerns/work/instruction_controller_concern.rb', line 7 def initialize_vars instantiate_work_classes not_found("no product id provided") unless params[:product_id] @auth_work_instruction_params = permitted_params.fetch(:instruction,{}) begin if @auth_shopping_product = @auth_shopping_product_class.find(params[:product_id]) @auth_shopping_product = @auth_shopping_product_class.find_self(params[:product_id],current_signed_in_resource) ## if the instruction id is provided, then it has to exist if params[:id] @auth_work_instruction = @auth_shopping_product.instructions.select{|c| c.id.to_s == params[:id] } not_found("no such object") if @auth_work_instruction.empty? @auth_work_instruction = @auth_work_instruction[0] else @auth_work_instruction = @auth_work_instruction_class.new(@auth_work_instruction_params) end else puts "product not found." end rescue Mongoid::Errors::DocumentNotFound @auth_shopping_product = @auth_shopping_product_class.new @auth_work_instruction = @auth_work_instruction_class.new(@auth_work_instruction_params) end end |
#new ⇒ Object
94 95 96 |
# File 'app/controllers/auth/concerns/work/instruction_controller_concern.rb', line 94 def new puts "the product is: #{@auth_shopping_product.to_s}" end |
#permitted_params ⇒ Object
okay so how to port this to the pathofast side ? we can just package the gem and see how it fares. that’s the best way the only remaining major issue will be the images and the only thing that has failed completely is the micro let me first build the create ?
109 110 111 |
# File 'app/controllers/auth/concerns/work/instruction_controller_concern.rb', line 109 def permitted_params pr = params.permit({:instruction => [:title,:description]}, :id, :product_id) end |
#show ⇒ Object
80 81 82 83 84 85 |
# File 'app/controllers/auth/concerns/work/instruction_controller_concern.rb', line 80 def show instantiate_work_classes ## so i will have to pass the product id as well. @auth_shopping_product = @auth_shopping_product_class.find(params[:product_id]) @auth_work_instruction = @auth_shopping_product.instructions.select{|c| c.id.to_s == params[:id]}[0] end |
#update ⇒ Object
61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'app/controllers/auth/concerns/work/instruction_controller_concern.rb', line 61 def update check_for_update(@auth_work_instruction) @auth_work_instruction.assign_attributes(@auth_work_instruction_params) @auth_shopping_product.instructions[get_index] = @auth_work_instruction @auth_shopping_product.save respond_to do |format| format.json do render json: @auth_work_instruction.to_json end format.html do render :partial => "show.html.erb", locals: {instruction: @auth_work_instruction, product: @auth_shopping_product} end end end |