app/controllers/cambium/admin_controller.rb in cambium-1.1.6 vs app/controllers/cambium/admin_controller.rb in cambium-1.2.0

- old
+ new

@@ -7,16 +7,23 @@ include Cambium::CambiumHelper def index respond_to do |format| - format.html do + scope = admin_table.scope + if scope.split('.').size > 1 + @collection = admin_model + scope.split('.').each do |s| + @collection = @collection.send(s) + end + else @collection = admin_model.send(admin_table.scope) - .page(params[:page] || 1).per(15) end + format.html do + @collection = @collection.page(params[:page] || 1).per(15) + end format.csv do - @collection = admin_model.send(admin_table.scope) send_data admin.to_csv(@collection) end end end @@ -28,11 +35,10 @@ def new @object = admin_model.new end def create - set_object @object = admin_model.new(create_params) if @object.save redirect_to(admin_routes.index, :notice => "#{admin_model.to_s} created!") else render 'new' @@ -50,19 +56,26 @@ else render 'edit' end end + def destroy + set_object + @object.destroy + redirect_to(admin_routes.index, :notice => "#{admin_model.to_s} deleted!") + end + private def set_object if admin_model.new.respond_to?(:slug) && params[:slug] slug = params[:"#{admin_model.to_s.underscore}_slug"] || params[:slug] @object = admin_model.find_by_slug(slug) else id = params[:"#{admin_model.to_s.underscore}_id"] || params[:id] @object = admin_model.find_by_id(id.to_i) end + not_found if @object.nil? @obj = @object end def authenticate_admin! authenticate_user!