Sha256: eb21a2884b280117176d4cf62a8add87f55ef25a165a3d2e210bc2b629b0461b

Contents?: true

Size: 1.72 KB

Versions: 3

Compression:

Stored size: 1.72 KB

Contents

module Dash
  class <%= plural_name.camelize %>Controller < DashController

    def index
      @meta_title = @title = <%= class_name %>.model_name.human(count: 2)
      <%= @instance_plural %> = <%= class_name %>.filter(params[:q]).page(params[:p].present? ? params[:p].to_i : 1).per(15)
    end

    def new
      @meta_title = @title = "#{t('dash.grid.create')} #{<%= class_name %>.model_name.human}"
      <%= @instance_singular %> = <%= class_name %>.new
      render :form
    end
    
    def create
      @meta_title = @title = "#{t('dash.grid.create')} #{<%= class_name %>.model_name.human}"
      <%= @instance_singular %> = <%= class_name %>.new(params[<%= @param_singular %>])
      if <%= @instance_singular %>.save
        redirect_with_flash <%= @index_path %>, :success, t('dash.flash.success.create'), params
      else
        flash_errors <%= @instance_singular %>
        render :form
      end
    end

    def show
      @meta_title = @title = "#{t('dash.grid.update')} #{<%= class_name %>.model_name.human}"
      <%= @instance_singular %> = <%= class_name %>.find(params[:id])
      render :form
    end

    def update
      @meta_title = @title = "#{t('dash.grid.update')} #{<%= class_name %>.model_name.human}"
      <%= @instance_singular %> = <%= class_name %>.find(params[:id])
      if <%= @instance_singular %>.update_attributes(params[<%= @param_singular %>])
        redirect_with_flash <%= @index_path %>, :success, t('dash.flash.success.update'), params
      else
        flash_errors <%= @instance_singular %>
        render :form
      end
    end

    def destroy
      <%= class_name %>.destroy params[:id]
      redirect_with_flash <%= @index_path %>, :success, t('dash.flash.success.destroy')
    end  

  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
rails_dash-0.1.2 lib/generators/dash/templates/resource_controller.rb
rails_dash-0.1.1 lib/generators/dash/templates/resource_controller.rb
rails_dash-0.1.0 lib/generators/dash/templates/resource_controller.rb