Module: Madmin::StaticModels::ResourceExtension
- Defined in:
- lib/madmin/static_models/resource_extension.rb
Overview
Prepended to Madmin::Resource's singleton class.
Instance Method Summary collapse
- #edit_path(record) ⇒ Object
- #infer_type(name) ⇒ Object
- #model_column_names ⇒ Object
- #readonly? ⇒ Boolean
-
#show_path(record) ⇒ Object
Static records can't be passed to polymorphic_path (no #becomes, not backed by ActiveModel routing), so build the paths by hand.
Instance Method Details
#edit_path(record) ⇒ Object
22 23 24 25 26 |
# File 'lib/madmin/static_models/resource_extension.rb', line 22 def edit_path(record) return super unless StaticModels.static_model?(model) "#{index_path}/#{record.id}/edit" end |
#infer_type(name) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/madmin/static_models/resource_extension.rb', line 28 def infer_type(name) return super unless StaticModels.static_model?(model) if model_column_names.include?(name.to_s) :string elsif model.respond_to?(:reflect_on_association) && (association = model.reflect_on_association(name)) type_for_association(association) else :string end end |
#model_column_names ⇒ Object
9 10 11 12 |
# File 'lib/madmin/static_models/resource_extension.rb', line 9 def model_column_names adapter = StaticModels.adapter_for(model) adapter ? adapter.column_names(model) : super end |
#readonly? ⇒ Boolean
5 6 7 |
# File 'lib/madmin/static_models/resource_extension.rb', line 5 def readonly? StaticModels.static_model?(model) || super end |
#show_path(record) ⇒ Object
Static records can't be passed to polymorphic_path (no #becomes, not backed by ActiveModel routing), so build the paths by hand.
16 17 18 19 20 |
# File 'lib/madmin/static_models/resource_extension.rb', line 16 def show_path(record) return super unless StaticModels.static_model?(model) "#{index_path}/#{record.id}" end |