Created
January 16, 2019 11:33
-
-
Save lalitlogical/5087f23d81e4caadb875dff5e4ba2821 to your computer and use it in GitHub Desktop.
Migrate RailsAdmin's model to ActiveAdmin's model
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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