Skip to content

Instantly share code, notes, and snippets.

@bbenezech
Created January 16, 2012 14:35
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save bbenezech/1621146 to your computer and use it in GitHub Desktop.
Save bbenezech/1621146 to your computer and use it in GitHub Desktop.
Create a RailsAdmin custom action
say "Create stub for '#{action_name = name.sub('rails_admin_', '')}' in gem '#{name}'. This may take a while"
run "rm -rf script/ config/ lib/tasks/"
run "rm -rf app/assets app/controllers app/helpers app/mailers app/models"
run "mkdir -p app/views/rails_admin/main"
inside "app/views/rails_admin/main" do
create_file "#{action_name}.html.haml", <<-END
%h2 Custom action loaded and active
%pre @abstract_model.inspect
%pre @object.inspect
END
end
inside "config/locales" do
create_file "#{action_name}.en.yml", <<-END
en:
admin:
actions:
#{action_name}:
title: "#{action_name.titleize}"
menu: "#{action_name.titleize} for %{model_label} '%{object_label}'"
breadcrumb: "#{action_name.titleize}"
link: "#{action_name.titleize}"
bulk_link: "#{action_name.titleize} selected %{model_label_plural}"
done: "#{action_name.titleize}ed"
END
end
inside "lib" do
append_file "#{name}.rb", <<-END
require 'rails_admin/config/actions'
module RailsAdmin
module Config
module Actions
class #{action_name.camelize} < Base
RailsAdmin::Config::Actions.register(self)
register_instance_option :object_level do
true
end
end
end
end
end
END
end
say "RailsAdmin action stub generator is done"
@jalada
Copy link

jalada commented Feb 6, 2013

Wait...what is with line 3?

@greenplastik
Copy link

DO NOT USE THIS FOR ANYTHING. THIS WILL DELETE YOUR APP

@ideadapt
Copy link

Its thought to be used to create a reusable plugin like action, and not to generate a new action within an existing rails app!
Use it like this:

rails plugin new rails_admin_<action_name> -m https://gist.github.com/bbenezech/1621146/raw/5268788e715397bf476c83d76d335f152095e659/rails_admin_action_creator --skip-gemfile --skip-bundle -T -O -S -J --full

More details at https://github.com/sferik/rails_admin/wiki/Custom-action

@abhishek77in
Copy link

IMHO - THIS DOES NOT DELETE YOUR APP

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment