I want to create a partials to render some data in index panel for different namespaces for DRY
I am currently writing
index do
render 'index', user: :user
end
//_index.html.arb
column :id
column 'Customer Name', :name
column :mobile
column :recipient_number
column :cash_in_hand do |customer|
number_to_currency(customer.cash_in_hand, unit: "\u20B9", precision: 2)
end
column "Due Balance" do |customer|
number_to_currency(customer.due_balance, unit: "\u20B9", precision: 2)
end
actions
To get the image file uploading work with Active Admin you need to specify your own form partial. Luckily for us, Active Admin provides a clean way of doing this. You just specify a partial name in a Active Admin resource configuration and whitelist the image param.
Active Admin is a Ruby on Rails plugin for generating administration style interfaces. It abstracts common business application patterns to make it simple for developers to implement beautiful and elegant interfaces with very little effort.
You can create a partial to render that data exactly like this
# app/admin/some_class.rb
index do
render 'admin/index', context: self
end
You probably will want to create a folder called 'admin' in views for these types of partials ...
# app/views/admin/_index.html.erb
<% context.instance_eval do
column :id
column 'Customer Name', :name
column :mobile
column :recipient_number
column :cash_in_hand do |customer|
number_to_currency(customer.cash_in_hand, unit: "\u20B9", precision: 2)
end
column "Due Balance" do |customer|
number_to_currency(customer.due_balance, unit: "\u20B9", precision: 2)
end
actions
end %>
I can confirm this works with .erb extention file and .haml but no guaranteeing others
This works for me in Rails 6 with:
#app/admin/some_class.rb
index do
render partial: 'active_admin/index', locals:{context: self}
end
and
#app/views/active_admin/_index.html.arb
context.instance_eval do
selectable_column
id_column
column :some_attribute
actions
end
This also satisfies locating the file in a shared place not specific to the admin/ space. It's useful because I have AA running with two separate user models and I often want to share the same code for index, show, etc with minor differences.
If needed, additional key-values can be passed in the locals hash for minor customization of the results.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With