Sha256: a3574c981788843470e7642060289b24b3a6cd346d709819e5f98fb262913455

Contents?: true

Size: 1.08 KB

Versions: 4

Compression:

Stored size: 1.08 KB

Contents

class PeopleController < ApplicationController
  before_action :set_person, only: [:show, :update, :destroy]

  # GET /people
  def index
    @people = Person.all

    render json: @people
  end

  # GET /people/1
  def show
    render json: @person
  end

  # POST /people
  def create
    @person = Person.new(person_params)

    if @person.save
      render json: @person, status: :created, location: @person
    else
      render json: @person.errors, status: :unprocessable_entity
    end
  end

  # PATCH/PUT /people/1
  def update
    if @person.update(person_params)
      render json: @person
    else
      render json: @person.errors, status: :unprocessable_entity
    end
  end

  # DELETE /people/1
  def destroy
    @person.destroy
  end

  private
    # Use callbacks to share common setup or constraints between actions.
    def set_person
      @person = Person.find(params[:id])
    end

    # Only allow a trusted parameter "white list" through.
    def person_params
      Yamls::Parameters.new(
        params,
        model: :person,
        action: :post
      ).permit
    end
end

Version data entries

4 entries across 2 versions & 1 rubygems

Version Path
yamls-0.2.2 example/rails5/app/controllers/people_controller.rb
yamls-0.2.2 example/rails6.0.0/app/controllers/people_controller.rb
yamls-0.2.1 example/rails5/app/controllers/people_controller.rb
yamls-0.2.1 example/rails6.0.0/app/controllers/people_controller.rb