Sha256: 99f19310d326b06e7f78621e58e8514e2e6f0093d3bd709e42b5495223a306fe
Contents?: true
Size: 1.58 KB
Versions: 2
Compression:
Stored size: 1.58 KB
Contents
module RailsDash class CrudController < ::DashController before_filter :model def index @meta_title = @title = "#{@model.model_name.human :count => 2}" @records = @model.list(page, filter) end def new @meta_title = @title = "#{t('global.add')} #{@model.model_name.human}" @record = @model.new render :form end def create @meta_title = @title = "#{t('global.add')} #{@model.model_name.human}" @record = @model.new(params[param]) if @record.save redirect_with_flash(index_path, :success, t('flash.success.add'), params) else flash_errors @record render :form end end def show @meta_title = @title = "#{t('global.view')} #{@model.model_name.human}" @record = @model.find(params[:id]) render :form end def update @meta_title = @title = "#{t('global.view')} #{@model.model_name.human}" @record = @model.find(params[:id]) if @record.update_attributes(params[param]) redirect_with_flash index_path, :success, t('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('flash.success.delete') end protected def model @model = Object.const_get self.class.name.split('::').last.gsub('Controller', '').singularize end def index_path send "dash_#{@model.name.tableize}_path" end def param @model.name.underscore.to_sym end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
rails_dash-0.0.2 | app/controllers/rails_dash/crud_controller.rb |
rails_dash-0.0.1 | app/controllers/rails_dash/crud_controller.rb |