Created by: gracewashere
The generator pulls column names and types from the database,
using the methods #column_names
and column_types
.
- Fill in missing mappings to
BaseDashboard#field_registry
.
References: http://edgeguides.rubyonrails.org/generators.html https://github.com/ryanb/nifty-generators
When the user runs rails generate dashboard order
,
they get a file app/dashboards/order_dashboard.rb
with the contents:
require "base_dashboard"
class OrderDashboard < BaseDashboard
# This method returns a hash
# that describes the type of each of the model's fields.
#
# Each different type represents an Administrate::Field object,
# which determines how the attribute is displayed
# on pages throughout the dashboard.
def attribute_types
{
id: :integer,
customer_id: :integer,
address_line_one: :string,
address_line_two: :string,
address_city: :string,
address_state: :string,
address_zip: :string,
created_at: :datetime,
updated_at: :datetime,
customer: :belongs_to,
line_items: :has_many,
}
end
# This method returns an array of attributes
# that will be displayed on the model's index page.
def index_page_attributes
attributes
end
# This method returns an array of attributes
# that will be displayed on the model's show page
def show_page_attributes
attributes
end
# This method returns an array of attributes
# that will be displayed on the model's form pages (`new` and `edit`)
def form_attributes
attributes - read_only_attributes
end
private
def attributes
[
:id,
:customer_id,
:address_line_one,
:address_line_two,
:address_city,
:address_state,
:address_zip,
:created_at,
:updated_at,
:customer,
:line_items,
]
end
def read_only_attributes
[
:id,
:created_at,
:updated_at,
]
end
end