module EasyAdminUi::CoreExt::ClassMethods
Public Instance Methods
controller_full_path()
click to toggle source
# File lib/easy_admin_ui/core_ext.rb, line 133 def controller_full_path File.join 'app/views', self.controller_path end
current_object()
click to toggle source
# File lib/easy_admin_ui/core_ext.rb, line 123 def current_object @item ||= current_model.find(params[:id]) if params[:id] @item ||= current_model.new(object_parameters) end
current_objects()
click to toggle source
# File lib/easy_admin_ui/core_ext.rb, line 115 def current_objects if defined?(Mongoid) && current_model.included_modules.include?(Mongoid::Document) @items = current_model.send(easy_options[:order_method] ? easy_options[:order_method] : :asc, easy_options[:order]).page(params[:page]).per(easy_options[:per_page]) else @items = current_model.order(easy_options[:order]).page(params[:page]).per(easy_options[:per_page]) end end
easy_admin(admin_options = {})
click to toggle source
# File lib/easy_admin_ui/core_ext.rb, line 8 def easy_admin(admin_options = {}) self.easy_options = admin_options self.easy_options[:include] ||= '' make_resourceful do actions :all response_for :index do |format| format.html do @options = self.easy_options override = File.join('app/views', self.controller_path, 'index.html.erb') if @items.blank? && params[:page] && params[:page].to_i > 1 redirect_to :action => :index else if File.exists?(override) render :template => override.gsub('app/views', '') else render :template => 'easy_admin_ui/index' end end end end response_for :show do |format| format.html do @options = self.easy_options override = File.join(controller_full_path, 'show.html.erb') if File.exists?(override) render :template => override.gsub('app/views', '') else render :template => 'easy_admin_ui/show' end end end [:new, :create_fails].each do |new_action| response_for new_action do |format| format.html do override = File.join(controller_full_path, 'new.html.erb') if File.exists?(override) render :template => override.gsub('app/views', '') else render :template => 'easy_admin_ui/new' end end end end response_for :create do |format| format.html do flash[:notice] = 'Created!' redirect_to :action => :index end format.js end [:edit, :update_fails].each do |edit_action| response_for edit_action do |format| format.html do override = File.join(controller_full_path, 'edit.html.erb') if File.exists?(override) render :template => override.gsub('app/views', '') else render :template => 'easy_admin_ui/edit' end end end end response_for :update do |format| format.html do flash[:notice] = 'Updated!' redirect_to :action => :index end format.js end response_for :destroy do |format| format.js do render :template => 'easy_admin_ui/destroy' end end eval(admin_options[:include]) end class_eval do def object_parameters if request.post? if respond_to?(:allowed_params) return allowed_params elsif respond_to?(:create_params) return create_params end elsif request.patch? || request.put? if respond_to?(:allowed_params) return allowed_params elsif respond_to?(:update_params) return update_params end end {} end def current_objects if defined?(Mongoid) && current_model.included_modules.include?(Mongoid::Document) @items = current_model.send(easy_options[:order_method] ? easy_options[:order_method] : :asc, easy_options[:order]).page(params[:page]).per(easy_options[:per_page]) else @items = current_model.order(easy_options[:order]).page(params[:page]).per(easy_options[:per_page]) end end def current_object @item ||= current_model.find(params[:id]) if params[:id] @item ||= current_model.new(object_parameters) end def instance_variable_name 'item' end helper_method :controller_full_path def controller_full_path File.join 'app/views', self.controller_path end end end
instance_variable_name()
click to toggle source
# File lib/easy_admin_ui/core_ext.rb, line 128 def instance_variable_name 'item' end
object_parameters()
click to toggle source
# File lib/easy_admin_ui/core_ext.rb, line 97 def object_parameters if request.post? if respond_to?(:allowed_params) return allowed_params elsif respond_to?(:create_params) return create_params end elsif request.patch? || request.put? if respond_to?(:allowed_params) return allowed_params elsif respond_to?(:update_params) return update_params end end {} end