<% module_namespacing do -%> class <%= class_name %> < <%= parent_class_name.classify %> <% if attributes_names.any? { |name| name == “position” } -%>
# Use acts_as_list to maintain position of the <%= class_name %> acts_as_list column: :position, top_of_list: 0 #, scope: :parent
<% end -%>
# Allow Pagination of <%= class_name %> collections paginates_per 25 # Log changes made to the <%= class_name %> audited only: %i[<%= attributes_names.join(" ") %>] # Generate human-readable tokens as params (friendly_id)
<%-
# Generate scaffold with name or title, and a `slug:uniq` field to enable friendly_id identifier_attribute_names = attributes_names.filter { |name| %w(name title).include?(name) } friendly_id_attribute = identifier_attribute_names.first if friendly_id_attribute && attributes_names.any? { |name| name == "slug" }
-%>
extend FriendlyId friendly_id :<%= friendly_id_attribute %>
<% else -%>
# extend FriendlyId # friendly_id :<%= friendly_id_attribute || "name" %>
<% end -%>
<%- identifier_attribute_names.each do |attribute_name| -%>
validates :<%= attribute_name %>, presence: true
<% end -%> <% attributes.select(&:reference?).each do |attribute| -%>
belongs_to :<%= attribute.name %><%= ', polymorphic: true' if attribute.polymorphic? %>
<% end -%> <% attributes.select(&:reference?).each do |attribute| -%>
belongs_to :<%= attribute.name %><%= ', polymorphic: true' if attribute.polymorphic? %>
<% end -%> <% attributes.select(&:rich_text?).each do |attribute| -%>
has_rich_text :<%= attribute.name %>
<% end -%> <% attributes.select(&:attachment?).each do |attribute| -%>
has_one_attached :<%= attribute.name %>
<% end -%> <% attributes.select(&:attachments?).each do |attribute| -%>
has_many_attached :<%= attribute.name %>
<% end -%> <% attributes.select(&:token?).each do |attribute| -%>
has_secure_token<% if attribute.name != "token" %> :<%= attribute.name %><% end %>
<% end -%> <% if attributes.any?(&:password_digest?) -%>
has_secure_password
<% end -%>
def to_s
<% if friendly_id_attribute -%>
<%= friendly_id_attribute %>_was # Use original <%= friendly_id_attribute %> for display labels
<% else -%>
"<%= class_name %>" # TODO: Provide a display label
<% end -%>
end
end <% end -%>