Sha256: 8d4f3be1186e07ee868e7cdb10ad031c0a910cbd9e4b16f9a555e983fe7d6a25

Contents?: true

Size: 1.66 KB

Versions: 12

Compression:

Stored size: 1.66 KB

Contents

class <%= controller_class_name %>Controller < Admin::ApplicationController
  before_action :set_<%= singular_table_name %>, only: %i[ show edit update destroy ]

  def index
    @search = <%= orm_class.all(class_name) %>.ransack(params[:q])

    respond_to do |format|
      format.html { @pagy, @<%= plural_table_name %> = pagy(@search.result) }
      format.csv  { render csv: @search.result }
    end
  end

  def show
  end

  def new
    @<%= singular_table_name %> = <%= orm_class.build(class_name) %>
  end

  def edit
  end

  def create
    @<%= singular_table_name %> = <%= orm_class.build(class_name, "#{singular_table_name}_params") %>

    if @<%= orm_instance.save %>
      redirect_to <%= redirect_resource_name %>, notice: <%= %("#{human_name} was successfully created.") %>
    else
      render :new, status: :unprocessable_entity
    end
  end

  def update
    if @<%= orm_instance.update("#{singular_table_name}_params") %>
      redirect_to <%= redirect_resource_name %>, notice: <%= %("#{human_name} was successfully updated.") %>
    else
      render :edit, status: :unprocessable_entity
    end
  end

  def destroy
    @<%= orm_instance.destroy %>
    redirect_to <%= index_helper %>_url, notice: <%= %("#{human_name} was successfully destroyed.") %>
  end

  private
    def set_<%= singular_table_name %>
      @<%= singular_table_name %> = <%= orm_class.find(class_name, "params[:id]") %>
    end

    def <%= "#{singular_table_name}_params" %>
      <%- if attributes_names.empty? -%>
      params.fetch(:<%= singular_table_name %>, {})
      <%- else -%>
      params.require(:<%= singular_table_name %>).permit(<%= permitted_params %>)
      <%- end -%>
    end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
administration-zero-0.0.12 lib/generators/admin/scaffold/templates/controller.rb.tt
administration-zero-0.0.11 lib/generators/admin/scaffold/templates/controller.rb.tt
administration-zero-0.0.10 lib/generators/admin/scaffold/templates/controller.rb.tt
administration-zero-0.0.9 lib/generators/admin/scaffold/templates/controller.rb.tt
administration-zero-0.0.8 lib/generators/admin/scaffold/templates/controller.rb.tt
administration-zero-0.0.7 lib/generators/admin/scaffold/templates/controller.rb.tt
administration-zero-0.0.6 lib/generators/admin/scaffold/templates/controller.rb.tt
administration-zero-0.0.5 lib/generators/admin/scaffold/templates/controller.rb.tt
administration-zero-0.0.4 lib/generators/admin/scaffold/templates/controller.rb.tt
administration-zero-0.0.3 lib/generators/admin/scaffold/templates/controller.rb.tt
administration-zero-0.0.2 lib/generators/admin/scaffold/templates/controller.rb.tt
administration-zero-0.0.1 lib/generators/admin/scaffold/templates/controller.rb.tt