Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- module Api
- module V1
- class IngredientMeasuresController < ApplicationController
- def index
- render json: IngredientMeasure.all
- end
- def create
- ingredient_measure = IngredientMeasure.new(params[:ingredient_id, :measure_id])
- if ingredient_measure.save
- render json: ingredient_measure
- else
- render json: {status: 500, err: 'Ingredient measure could not be created'}
- end
- end
- private
- def ingredient_measure_params
- params.require(:ingredient_measure).permit(:ingredient_id, :measure_id)
- end
- end
- end
- end
- {
- "measure_id" : 3,
- "ingredient_id":3
- }
- create_table "ingredient_measures", force: :cascade do |t|
- t.datetime "created_at", null: false
- t.datetime "updated_at", null: false
- t.bigint "ingredient_id"
- t.bigint "measure_id"
- t.index ["ingredient_id"], name: "index_ingredient_measures_on_ingredient_id"
- t.index ["measure_id"], name: "index_ingredient_measures_on_measure_id"
- end
- ingredient_measure = IngredientMeasure.new(ingredient_measure_params)
- {
- "ingredient_measure": {
- "measure_id" : 3,
- "ingredient_id" : 3
- }
- }
- params.require(:ingredient_measure).permit(:ingredient_id, :measure_id)
- IngredientMeasure.new(ingredient_measure_params)
Add Comment
Please, Sign In to add comment