Sha256: 8dcc18b3052269f7034e320cb4aae781b9b4c1fa901360e6ba6d3ed417afdbeb
Contents?: true
Size: 1.95 KB
Versions: 1
Compression:
Stored size: 1.95 KB
Contents
module RailsDash class CrudController < ::DashController before_filter :model def index @meta_title = @title = "#{@model.model_name.human :count => 2}" @records = @model.filter(params[:q]).page(params[:p].present? ? params[:p].to_i : 1).per(15) end def new @meta_title = @title = "#{t('dash.grid.add')} #{@model.model_name.human}" define_record :new render :form end def create @meta_title = @title = "#{t('dash.grid.add')} #{@model.model_name.human}" define_record :create if @record.save redirect_with_flash(index_path, :success, t('dash.flash.success.add'), params) else flash_errors @record render :form end end def show @meta_title = @title = "#{t('dash.grid.edit')} #{@model.model_name.human}" define_record :show render :form end def update @meta_title = @title = "#{t('dash.grid.edit')} #{@model.model_name.human}" define_record :update if @record.update_attributes(params[param]) redirect_with_flash index_path, :success, t('dash.flash.success.edit'), params else flash_errors @record render :form end end def destroy @model.destroy params[:id] redirect_with_flash index_path, :success, t('dash.flash.success.destroy') end protected def define_record(context) if context == :new @record = @model.new elsif context == :create @record = @model.new(params[param]) else @record = @model.find(params[:id]) end send :alter_record, context if respond_to? :alter_record end def model @model = Object.const_get self.class.name.split('::').last.gsub('Controller', '').singularize end def index_path main_app.url_for(:controller => "dash/#{@model.name.tableize}", :action => 'index') end def param @model.name.underscore.to_sym end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
rails_dash-0.0.6 | app/controllers/rails_dash/crud_controller.rb |