app/controllers/cambium/admin_controller.rb in cambium-1.2.3 vs app/controllers/cambium/admin_controller.rb in cambium-1.3.0
- old
+ new
@@ -8,20 +8,26 @@
include Cambium::CambiumHelper
def index
respond_to do |format|
scope = admin_table.scope
- if scope.split('.').size > 1
- @collection = admin_model
- scope.split('.').each do |s|
- @collection = @collection.send(s)
- end
+ if params[:sort_by]
+ @collection = admin_model.unscoped
+ .order("#{params[:sort_by]} #{params[:order] || 'asc'}")
else
- @collection = admin_model.send(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)
+ end
end
format.html do
@collection = @collection.page(params[:page] || 1).per(15)
+ render :layout => false if params[:no_layout]
end
format.csv do
send_data admin.to_csv(@collection)
end
end
@@ -37,11 +43,13 @@
end
def create
@object = admin_model.new(create_params)
if @object.save
- redirect_to(admin_routes.index, :notice => "#{admin_model.to_s} created!")
+ redirect_to(
+ admin_routes.index,
+ :notice => "#{admin_model.to_s.gsub(/Cambium::/, '')} created!")
else
render 'new'
end
end
@@ -50,19 +58,23 @@
end
def update
set_object
if @object.update(update_params)
- redirect_to(admin_routes.index, :notice => "#{admin_model.to_s} updated!")
+ redirect_to(
+ admin_routes.index,
+ :notice => "#{admin_model.to_s.gsub(/Cambium::/, '')} updated!")
else
render 'edit'
end
end
def destroy
set_object
@object.destroy
- redirect_to(admin_routes.index, :notice => "#{admin_model.to_s} deleted!")
+ redirect_to(
+ admin_routes.index,
+ :notice => "#{admin_model.to_s.gsub(/Cambium::/, '')} deleted!")
end
private
def set_object