Sha256: 4e9c96fd3f9dabb39ce5a13419cc9db3f09a30532132f6e29840cdc4e6687f82
Contents?: true
Size: 1.52 KB
Versions: 28
Compression:
Stored size: 1.52 KB
Contents
class CMS::BaseController < ApplicationController before_filter :admin! before_filter :set_active layout 'cms' before_filter :find_record, only: [:show, :edit, :update, :destroy] before_filter :set_element_variable, only: [:show, :edit, :update, :destroy] respond_to :html, :json def index @records = if params[:search].blank? subject.order('id asc') .page(params[:page]).per(100) else subject.search(params[:search]).page(params[:page]).per(100) end set_collection_variable respond_with(@records) end def new @record = subject.new set_element_variable respond_with(@record) end def create @record = subject.create(params[subject.model_name.element]) set_element_variable respond_with @record end def show respond_with @record end def edit respond_with @record end def update @record.update_attributes params[subject.model_name.element] respond_with @record end def destroy @record.destroy respond_with @record end protected def respond_with object super [:cms, object] end def find_record @record = subject.find(params[:id]) end def set_collection_variable instance_variable_set :"@#{subject.model_name.collection}", @records end def set_element_variable instance_variable_set :"@#{subject.model_name.element}", @record end def admin! unless signed_in? && current_user.role.admin? auth_failed end end def set_active @active_page = /cms/ end end
Version data entries
28 entries across 28 versions & 1 rubygems