Sha256: c6c6166e4e15750315d1e239eabd64f6b9e1dd5c2a406dab8c17288c6d9a14b3
Contents?: true
Size: 1.7 KB
Versions: 1
Compression:
Stored size: 1.7 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}" @record = @model.new render :form end def create @meta_title = @title = "#{t('dash.grid.add')} #{@model.model_name.human}" @record = @model.new(params[param]) 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}" @record = @model.find(params[:id]) render :form end def update @meta_title = @title = "#{t('dash.grid.edit')} #{@model.model_name.human}" @record = @model.find(params[:id]) 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 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.5 | app/controllers/rails_dash/crud_controller.rb |