Sha256: fc9c9b5ea00ed15a53ae67315e4f5b36a6610960ff4176a1ed6bea1849e1bb47

Contents?: true

Size: 1.49 KB

Versions: 1

Compression:

Stored size: 1.49 KB

Contents

<%= %Q(class #{config[:namespace_cap]}::#{config[:model_cap_plu]}Controller < #{config[:namespace_cap]}::BaseController
  before_action :set_#{config[:model]}, only: [:show, :edit, :update, :destroy]

  def index
    @#{config[:model_plu]} = #{config[:model_cap]}.all
  end

  def show
  end

  def new
    @#{config[:model]} = #{config[:model_cap]}.new
  end

  def edit
  end

  def create
    @#{config[:model]} = #{config[:model_cap]}.new(#{config[:model]}_params)
    respond_to do |format|
      if @#{config[:model]}.save
        format.html { redirect_to [:#{config[:namespace]}, @#{config[:model]}], notice: '#{config[:model_cap]} was successfully created.' }
      else
        format.html { render :new }
      end
    end
  end

  def update
    respond_to do |format|
      if @#{config[:model]}.update(#{config[:model]}_params)
        format.html { redirect_to [:#{config[:namespace]}, @#{config[:model]}], notice: '#{config[:model_cap]} was successfully updated.' }
      else
        format.html { render :edit }
      end
    end
  end

  def destroy
    @#{config[:model]}.destroy
    respond_to do |format|
      format.html { redirect_to #{config[:namespace]}_#{config[:model_plu]}_url, notice: '#{config[:model_cap]} was successfully destroyed.' }
    end
  end

  private
    def set_#{config[:model]}
      @#{config[:model]} = #{config[:model_cap]}.find(params[:id])
    end

    def #{config[:model]}_params
      params.require(:#{config[:model]}).permit(#{build_params_controller})
    end
end
)%>

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
easy_cms-0.1.0 lib/generators/easy_cms/model/templates/controllers/model_controller.erb