So I would like to have a shortened table with batch actions.
ActiveAdmin.register User do
batch_action :acitve do |selection|
User.find(selection).each do |user|
user.active! true
end
end
filter :email
index do
column :id
column :first_name
column :last_name
column :email
column :sign_in_count
default_actions
end
end
However batch action box is greyd out. It's understanbale because nothing is selected. However when I use default index settings (no columns specification), the checkbox stays there. How can I have a default checkbox with custom columns?
according to this (Customizing Table Columns part) you need to add
index do
selectable_column #batch actions checkboxes column
column ...
...
end
to render checkboxes
Related
I am trying to display a box at the bottom of my ActiveAdmin index page where it will total all of the values of the collection and display this total value. I am trying to sum the value of the column :number_books and I am currently using this code as suggested when someone answered a similar question a few years ago.
This does not appear to be having any impact on my index page as nothing is visibly changing on the index page for :orders.
Any help is greatly appreciated!
ActiveAdmin.register Order do
index do
column :email
column :customer_name
column :number_books
column :street_address
column :state
column :zip_code
column :total
default_actions
div class: "panel" do
h3 "Total amount: #{collection.pluck(:number_books).reduce(:+)}"
end
end
end
I found out I had to define this new index page I was creating as the default, otherwise activeadmin uses the default index page and ignores my custom one. I also had to change default_actions to simply actions and this now works great!
the working code is:
ActiveAdmin.register Order do
index default: true do
column :email
column :customer_name
column :number_books
column :street_address
column :state
column :zip_code
column :total
actions
div class: "panel" do
h3 "Total amount: #{collection.pluck(:number_books).reduce(:+)}"
end
end
end
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
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.
I have a rails 3 application which uses the ActiveAdmin gem.
If I do not customizes my models, 3 actions are enabled in each line of my model : show, edit, delete
But if I customizes my model, the actions disappear.
Model not customized showing the actions (users.rb) :
ActiveAdmin.register User, as: 'Users_full' do
menu :parent => 'Users'
end
Custom model not showing actions (companies.rb) :
ActiveAdmin.register Company do
index do
selectable_column
column :name
column :url
end
csv do
column :name
column :url
end
end
Is there a way to get actions in customized models ? I have already tried to add : actions :all, config.batch_actions = true and action_item to my companies.rb file but nothing change.
Add the actions, like:
index do
selectable_column
column :name
column :url
actions
end
You're defining the index page's content, and that content includes the actions-if you omit them, they won't show up.
I'm using ejholmes Active_admin Editor and it's working fine but in my active admin index I see the html code with tags and not the correct output. I do use .html_safe in my views but here's my active admin's posts.rb
...
index.do
column :id
column "Titolo", :title
column "Corpo news", :body
column "Creato il", :created_at
column "Modificato il", :updated_at
column :link
column "Link Immagine", :image_url
bool_column :attivo
default_actions
end
...
I want to have my "Corpo news" column rendered.
Thanks for the help!
I guess you need to use the method .to_html as you can see by the source
So in the view you need to call
body.to_html
I am using ActiveAdmin to render an index table for a model.
The config looks like this:
ActiveAdmin.register User do
index do
selectable_column
column :username
column "Email" do |u|
raw "<span title='#{u.email}'>#{truncate(u.email, length: 14)}</span>"
end
end
end
The rendered HTML for the "email" TD looks like this:
<td class=""><span title="useremail#example.com">useremail...</span></td>
I have tried passing class: 'foo' before the block and a few things like that but none have worked.
All of the columns that are not being created with the block syntax are getting a class attribute equal to the field name.
How do I set the class for the TD when using a block to render the column?
you have to override build_table_cell method,
you can take needed code here https://gist.github.com/3995962
put it to initializers folder.
now you can use it like
column(:status, :sortable => 'enabled', :class=>'status') do |row|
#some logic
end