Skip to content

@jasperkennis /active_admin.rb forked from dpmccabe/strong_admin.rb
Created

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
# config/initializers/active_admin.rb
ActiveAdmin.setup do |config|
# All the ActiveAdmin config stuf
end
Dir[ File.join(Rails.root, "lib", "active_admin_extentions", "*.rb") ].each {|l| require l }
# lib/active_admin_extentions/strong_admin.rb
module StrongAdmin
extend ActiveSupport::Concern
def initialize
@instance_name = active_admin_config.resource_name.gsub(/(.)([A-Z])/,'\1_\2').downcase
@klass = active_admin_config.resource_name.constantize
@column_names = @klass.columns.map do |column|
unless [:id, :created_at, :updated_at].include?(column.name.to_sym)
case column.type
when :datetime, :date, :time
([column.name.to_sym] + (1..5).inject([]) { |acc, x| acc << :"#{column.name}(#{x}i)" })
else
column.name.to_sym
end
end
end.flatten
super
end
def create
resource_obj = instance_variable_set("@#{@instance_name}", @klass.new(params[@instance_name.to_sym].permit!))
if resource_obj.save
redirect_to send("admin_#{@instance_name}_path", resource_obj), notice: "Created #{@instance_name}."
else
render :new
end
end
def update
resource_obj = instance_variable_set("@#{@instance_name}", @klass.find(params[:id]))
if resource_obj.update_attributes(params[@instance_name.to_sym].permit!)
redirect_to send("admin_#{@instance_name}_path", resource_obj), notice: "Updated #{@instance_name}."
else
render :edit
end
end
end
# app/admin/whatever.rb
ActiveAdmin.register Whatever do
controller do; include StrongAdmin; end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.