Sha256: 4528ae562c51935f1fe41388e9f67f991bb5a5ee206919ff2a16199d026fc804

Contents?: true

Size: 1.21 KB

Versions: 1

Compression:

Stored size: 1.21 KB

Contents

<% module_namespacing do -%>
class <%= model_klass.name.pluralize %>Controller < ApplicationController
  <%- if actions?('index') -%>
  def index
    <%= file_name.pluralize %> = <%= resource_klass %>.all(params)
    respond_with(<%= file_name.pluralize %>)
  end
  <%- end -%>
  <%- if actions?('show') -%>

  def show
    <%= file_name %> = <%= resource_klass %>.find(params)
    respond_with(<%= file_name.pluralize %>)
  end
  <%- end -%>
  <%- if actions?('create') -%>

  def create
    <%= file_name %> = <%= resource_klass %>.build(params)

    if <%= file_name %>.save
      respond_with(<%= file_name %>)
    else
      render jsonapi_errors: <%= file_name %>
    end
  end
  <%- end -%>
  <%- if actions?('update') -%>

  def update
    <%= file_name %> = <%= resource_klass %>.find(params)

    if <%= file_name %>.update_attributes
      respond_with(<%= file_name %>)
    else
      render jsonapi_errors: <%= file_name %>
    end
  end
  <%- end -%>
  <%- if actions?('destroy') -%>

  def destroy
    <%= file_name %> = <%= resource_klass %>.find(params)

    if <%= file_name %>.destroy
      render json: { meta: {} }
    else
      render jsonapi_errors: <%= file_name %>
    end
  end
  <%- end -%>
end
<% end -%>

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
jsonapi_compliable-1.0.alpha.2 lib/generators/jsonapi/templates/controller.rb.erb