Rails 3. How to Add a Helper That Activeadmin Will Use

Rails Active Admin - create helper function that wraps around column()

You can break up the IndexTableFor class in ActiveAdmin by placing the following inside an initializer. I placed it in config/initializers/active_admin_monkey_patches.rb

module ActiveAdmin
module Views
class IndexAsTable < ActiveAdmin::Component
class IndexTableFor < ::ActiveAdmin::Views::TableFor
def rename_column str, attr
column(str) do |obj|
obj.send(attr)
end
end
def img_column attr
column(attr) do |obj|
attachment_img(obj.send(attr))
end
end
def truncate_column attr, length
column(attr) do |obj|
obj.send(attr).try(:truncate, length)
end
end
end
end
end
end

Restart your rails server when making changes, as it is initializer code. Perhaps read the gem source, which in my case was located at

~/.rvm/gems/ruby-3.1.2@chirails/gems/activeadmin-2.13.1/lib/active_admin/views/index_as_table.rb

I found the location through running

bundle info activeadmin

How to custom actions method helper in active admin

To setup links to View, Edit and Delete a resource, use the actions method:

index do
selectable_column
column :title
actions
end

You can also append custom links to the default links:

index do
selectable_column
column :title
actions do |post|
link_to "Preview", admin_preview_post_path(post), class: "member_link"
end
end

Or forego the default links entirely:

index do
column :title
actions defaults: false do |post|
link_to "View", admin_post_path(post)
end
end

In case you prefer to list actions links in a dropdown menu:

index do
selectable_column
column :title
actions dropdown: true do |post|
item "Preview", admin_preview_post_path(post)
end
end

Reference: http://activeadmin.info/docs/3-index-pages/index-as-table.html#defining-columns

Ruby on Rails and ActiveAdmin: add all object all at once instead add one by one

Using for the array the as: :select form input with multi-select should help. Something like this:

sub_c.input :items, as: :select, 
collection: courses_collection,
multiple: true

Rails-style helper for active_admin pages using namespace

No, there is no helper like this, but you can do the following:

url_for(action: "batch_action", controller: "#{ActiveAdmin.config.default_namespace}/rewards")

activeadmin dropdown pass values with helper method to collection

I would put the hash variable in the ActiveRecord model as a constant. Then you can use:

attributes_table_for example do
row("Name") { MyModel::HASH_CONSTANT[example.name.to_sym] }
end

The hash should be op1: "apple" pairs, not "apple" => "op1"



Related Topics



Leave a reply



Submit