Skip to content

Instantly share code, notes, and snippets.

@lalitlogical
Created January 16, 2019 11:33
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 lalitlogical/5087f23d81e4caadb875dff5e4ba2821 to your computer and use it in GitHub Desktop.
Save lalitlogical/5087f23d81e4caadb875dff5e4ba2821 to your computer and use it in GitHub Desktop.
Migrate RailsAdmin's model to ActiveAdmin's model
class AdminGenerator < Rails::Generators::Base
argument :name, type: :string
source_root File.expand_path('../templates', __FILE__)
desc "Generates required files."
def copy_controller_and_spec_files
@model = name.to_s.constantize
@attributes = @model.attribute_names.reject{|c| c.match(/^_id/)}.map(&:to_sym)
template "resource.rb", "app/admin/#{name.underscore}.rb"
end
end
ActiveAdmin.register <%= name %> do
permit_params <%= @attributes.to_s.gsub(/\[|\]/,'') %>
index do |<%= name.underscore %>|
selectable_column
id_column
<% @attributes.each do |column_name| -%>
column :<%= column_name %>
<% end %>
actions
end
show do
attributes_table do
<% @attributes.each do |column_name| -%>
row :<%= column_name %>
<% end %>
end
end
form do |f|
f.inputs do
<% @attributes.each do |column_name| -%>
f.input :<%= column_name %>
<% end %>
end
actions
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment