daily pastebin goal
51%
SHARE
TWEET

Untitled

a guest Jun 22nd, 2018 62 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. module Api
  2.   module V1
  3.     class IngredientMeasuresController < ApplicationController
  4.  
  5.     def index
  6.       render json: IngredientMeasure.all
  7.     end
  8.  
  9.     def create
  10.       ingredient_measure = IngredientMeasure.new(params[:ingredient_id, :measure_id])
  11.       if ingredient_measure.save
  12.         render json: ingredient_measure
  13.       else
  14.         render json: {status: 500, err: 'Ingredient measure could not be created'}
  15.       end
  16.     end
  17.     private
  18.  
  19.     def ingredient_measure_params
  20.       params.require(:ingredient_measure).permit(:ingredient_id, :measure_id)
  21.      end
  22.    end
  23.  end
  24. end
  25.    
  26. {      
  27.     "measure_id" : 3,
  28.     "ingredient_id":3
  29. }
  30.    
  31. create_table "ingredient_measures", force: :cascade do |t|
  32. t.datetime "created_at", null: false
  33. t.datetime "updated_at", null: false
  34. t.bigint "ingredient_id"
  35. t.bigint "measure_id"
  36. t.index ["ingredient_id"], name: "index_ingredient_measures_on_ingredient_id"
  37. t.index ["measure_id"], name: "index_ingredient_measures_on_measure_id"
  38. end
  39.    
  40. ingredient_measure = IngredientMeasure.new(ingredient_measure_params)
  41.    
  42. {  
  43.   "ingredient_measure": {    
  44.     "measure_id" : 3,
  45.     "ingredient_id" : 3
  46.   }
  47. }
  48.    
  49. params.require(:ingredient_measure).permit(:ingredient_id, :measure_id)
  50.    
  51. IngredientMeasure.new(ingredient_measure_params)
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top