I realize that the purpose of rails_admin is supposed to essentially be a model admin tool, but I would like to have a list view for a model and include attributes of associated models in the list of the of model.
For example. I have a scale model and a container model. The container has an attribute 'weight', and the scale is associated via a 'has_one' relationship to container.
How can I include scale.container.weight in the scale model list view?
And example of my current Scale model is:
class Scale < ActiveRecord::Base
attr_accessible :activated, :cluster, :name, :plant, :status, :timer, :unauthorized, :uid, :container_id, :customer_id
has_one :container
rails_admin do
list do
field :name
field :activated
field Scale.container.weight # This is what I'm trying to include. However, this certainly doesn't produce the desired results.
end
end
end
Thanks!
--
You received this message because you are subscribed to the Google Groups "rails_admin" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rails_admin...@googlegroups.com.
To post to this group, send email to rails...@googlegroups.com.
Visit this group at http://groups.google.com/group/rails_admin?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
class Scale < ActiveRecord::Base
has_one :container
delegate :
weight, to: :container, prefix: true
rails_admin do
list do
field :name
field :
activated
field :container_weight do
searchable false # AR sorting/searching probably don't work out of the box with delegates, I'm not an expert on this
end
end
end
end
class Scale < ActiveRecord::Base
has_one :container
rails_admin do
list do
field :name
field :
activated
field :container_weight do
def value
bindings[:object].
container.weight
end
end
end
end
end
config.model Model do
list do
field :assos_field do
pretty_value do
bindings[:object].assos_field.your_field
end
end
include_all_fields
end
end