Sha256: 988d30c0a759f1520e1a18467abbda4b5c24d968ad901cfdb5f651f2fbb414da
Contents?: true
Size: 1.65 KB
Versions: 7
Compression:
Stored size: 1.65 KB
Contents
class Admin::<%= class_name.pluralize %>Controller < Admin::Cms::BaseController before_action :build_<%= file_name %>, :only => [:new, :create] before_action :load_<%= file_name %>, :only => [:show, :edit, :update, :destroy] def index @<%= file_name.pluralize %> = <%= class_name %>.page(params[:page]) end def show render end def new render end def edit render end def create @<%= file_name %>.save! flash[:success] = '<%= class_name.titleize %> created' redirect_to :action => :show, :id => @<%= file_name %> rescue ActiveRecord::RecordInvalid flash.now[:error] = 'Failed to create <%= class_name.titleize %>' render :action => :new end def update @<%= file_name %>.update_attributes!(<%= file_name %>_params) flash[:success] = '<%= class_name.titleize %> updated' redirect_to :action => :show, :id => @<%= file_name %> rescue ActiveRecord::RecordInvalid flash.now[:error] = 'Failed to update <%= class_name.titleize %>' render :action => :edit end def destroy @<%= file_name %>.destroy flash[:success] = '<%= class_name.titleize %> deleted' redirect_to :action => :index end protected def build_<%= file_name %> @<%= file_name %> = <%= class_name %>.new(<%= file_name %>_params) end def load_<%= file_name %> @<%= file_name %> = <%= class_name %>.find(params[:id]) rescue ActiveRecord::RecordNotFound flash[:error] = '<%= class_name.titleize %> not found' redirect_to :action => :index end def <%= file_name %>_params params.fetch(:<%= file_name %>, {}).permit(<%= model_attrs.collect{|attr| ":#{attr.name}"}.join(', ') %>) end end
Version data entries
7 entries across 7 versions & 1 rubygems