Skip to content

Instantly share code, notes, and snippets.

@mrbrdo
Created October 19, 2012 13:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mrbrdo/3918135 to your computer and use it in GitHub Desktop.
Save mrbrdo/3918135 to your computer and use it in GitHub Desktop.
activeadmin strong parameters extension
module StrongAdmin
extend ActiveSupport::Concern
def initialize
@instance_name = active_admin_config.resource_class.name.underscore.to_sym
@klass = active_admin_config.resource_class
super
end
def create
resource_obj = instance_variable_set("@#{@instance_name}", @klass.new(params[@instance_name].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].permit!)
redirect_to send("admin_#{@instance_name}_path", resource_obj), notice: "Updated #{@instance_name}."
else
render :edit
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment