<repo_name>mickaelpham/blog<file_sep>/app/models/author.rb
class Author < ApplicationRecord
  default_scope { order(updated_at: :desc) }
  validates :display_name, :email, presence: true
end
<file_sep>/app/serializers/author_serializer.rb
class AuthorSerializer < ActiveModel::Serializer
  attributes :id,
    :display_name,
    :email,
    :biography,
    :created_at,
    :updated_at
end
<file_sep>/app/controllers/authors_controller.rb
class AuthorsController < ApplicationController
  before_action :set_author, only: [:show, :update, :destroy]

  # GET /api/authors
  def index
    @authors = Author.all

    render json: @authors
  end

  # GET /api/authors/1
  def show
    render json: @author
  end

  # POST /api/authors
  def create
    @author = Author.new(author_params)

    if @author.save
      render json: @author, status: :created, location: @author
    else
      render json: @author,
        status: :unprocessable_entity,
        serializer: ActiveModel::Serializer::ErrorSerializer
    end
  end

  # PATCH/PUT /api/authors/1
  def update
    if @author.update(author_params)
      render json: @author
    else
      render json: @author,
        status: :unprocessable_entity,
        serializer: ActiveModel::Serializer::ErrorSerializer
    end
  end

  # DELETE /api/authors/1
  def destroy
    @author.destroy
  end

  private

  # Use callbacks to share common setup or constraints between actions.
  def set_author
    @author = Author.find(params[:id])
  end

  # Only allow a trusted parameter "white list" through.
  def author_params
    ActiveModelSerializers::Deserialization.jsonapi_parse(
      params,
      only: ['display-name', :email, :biography]
    )
  end
end
<file_sep>/frontend/app/routes/authors/show.js
import Ember from 'ember';

export default Ember.Route.extend({

  notify: Ember.inject.service('notify'),

  model(params) {
    return this.store.findRecord('author', params.id);
  },

  deactivate() {
    this.controller.get('model').rollbackAttributes();
  },

  actions: {

    saveAuthor() {
      let author = this.controller.get('model');
      author.save().then(() => {
        let name = author.get('displayName') ? author.get('displayName') : 'Author';
        this.get('notify').success(`${name} saved`);
      }).catch(() => {
        this.get('notify').alert("Couldn't save author");
      });
    },

    onCancel() {
      this.transitionTo('authors.index');
    },

    onDelete() {
      let author = this.controller.get('model');
      author.deleteRecord();
      author.save().then(() => {
        let name = author.get('displayName') ? author.get('displayName') : 'Author';
        this.get('notify').success(`${name} deleted`);
        this.transitionTo('authors.index');
      });
    }

  }

});
