Activeadmin registers a page on a single file, in which it has all the logic: Index, Show, Edit, etc.
I would like to split, let's say, task.rb into task_index.rb, task_show.rb, task_edit.rb, etc.
So, how should you do that?
NOTE: I know that making an ActiveAdmin.register block in each file (it appends if Task exists) will do the work, but this question aims for a general approach rather than solving this specific inquiry.
-- admin/task.rb
#encoding: utf-8
ActiveAdmin.register Task do
[Lot's of actions]
member_action....
member_action....
member_action....
batch_action....
[Index stuff]
filter....
scope....
scope....
scope....
index do
column...
column...
column...
column...
end
[Edit stuff]
form do |f|
f.input....
f.input....
f.input....
f.input....
f.input....
end
[etc etc etc]
end
----------------
I'm thinking of modules, but I can't figure out how to.
That is how I do this
module source
module ResourceDSL
module ActsAsClone
def acts_as_clone
controller do
def new
instance_variable_name = active_admin_config.resource_class.to_s.underscore
resource = active_admin_config.resource_class.find(params[:id]) rescue nil
attrs = resource.nil? ? {} : resource.attributes
resource = active_admin_config.resource_class.new(attrs)
instance_variable_set("##{instance_variable_name}", resource)
end
end
action_item :only => [:show, :edit] do
if can? :create, resource and (!resource.respond_to?(:live?) or resource.live?)
link_to "Copy", :action => :new, :id => resource.id
end
end
end
end
end
including to ActiveAdmin::ResourceDSL
ActiveAdmin::ResourceDSL.send :include, ResourceDSL::ActsAsClone
And then you can
ActiveAdmin.register Account do
menu :parent => "Billing", :priority => 10
acts_as_clone
end
Related
I was using below line of code to edit word document's textbox. It is working pretty well.
wdDoc.Shapes("T1").TextFrame.TextRange.Text = sh.Range("Q2"). Value
But now I made some changes in my Word document (template file).
I Grouped few items with Shapes("T1").So now Shapes("T1") is inside Group(3).
Now code give error, because it can't find Shapes("T1").
How can I reference Shapes("T1") within Group (3)?
Thank you.
Only property I have found is Shape.GroupItems
Here is the solution:
With wdDoc.Shapes("Group 3")
For x = 1 To .GroupItems.Count
If .GroupItems(x).Name = "T1" Then
With .GroupItems(x)
.TextFrame.TextRange.Text = sh.Range("Q2").Value
End With
End If
Next
End With
Networks contains a has_one relationship for vlans.
Vlans contains a belongs_to relationship for networks.
When I create a new network, I want to have the option of either selecting an existing vlan by vlanid -or- creating a new vlan for the new network.
I have made it as far as being able to create a brand new vlan when I create a network, but I would like to be able to select an existing vlan -or- create a new one.
app/models/network.rb
class Network < ApplicationRecord
has_one :vlan
accepts_nested_attributes_for :vlan, allow_destroy: true
end
app/models/vlan.rb
class Vlan < ApplicationRecord
belongs_to :network
end
db/migrate/create_network.rb
class CreateNetworks < ActiveRecord::Migration[5.2]
def change
create_table :networks do |t|
t.string :comment
t.string :name
t.timestamps
end
end
end
db/migrate/create_vlan.rb
class CreateVlans < ActiveRecord::Migration[5.2]
def change
create_table :vlans do |t|
t.string :comment
t.integer :vlanid
t.belongs_to :network
t.timestamps
end
end
end
app/admin/networks.rb
ActiveAdmin.register Network do
permit_params :comment, :name, vlan_attributes: [ :id, :vlanid, :comment, :_destroy, :_edit ]
index do
selectable_column
column "Network Name" do |i|
i.name
end
column :comment
column "VLAN ID" do |i|
i.vlan.vlanid
end
column "VLAN Comment" do |i|
i.vlan.comment
end
actions
end
show do
attributes_table do
row :name
row :comment
end
panel 'vlan' do
table_for network.vlan do
column :vlanid
column :comment
end
end
end
form do |f|
f.inputs 'Details' do
f.input :name
f.input :comment
end
f.inputs 'Vlans' do
f.has_many :vlan do |c|
c.input :vlanid
c.input :comment
end
end
f.actions
end
end
app/admin/vlans.rb
ActiveAdmin.register Vlan do
belongs_to :network
permit_params :comment, :vlanid
end
I've tried using something like the following in app/admin/networks.rb
panel 'vlan' do
table_for network.vlan do
column :vlanid, :as => :select
column :comment
end
end
I do get a drop-down in this instance, but the only values are "Yes" and "No".
This is my first time delving into activeadmin and I'm stumped.
I've seen some similar questions posted around, but none of the answers I've seen seemed to apply to this specific situation.
Any help is appreciated.
HI I am working on rails 4.2.4 app and i am using sorcery for authentication, cancancan for authorization.. so far so good i can login and users can do as well .... I am trying to add activeadmin for admin dashboard I so far set up almost everything but when i fire up the link http://localhost:3000/admin when logged in the app as admin i get the error :
undefined method `destroy_user_session_path' for
:ActiveAdmin::Views::TabbedNavigation
here are my modules:
Activeadmin.rb
ActiveAdmin.setup do |config|
config.site_title = "title goes here"
def authenticate_user!
if !current_user.admin?
redirect_to new_user_session_path
end
end
config.authentication_method = :authenticate_user!
config.current_user_method = :current_user
config.logout_link_method = :delete
config.logout_link_path = :destroy_user_session_path
config.batch_actions = true
config.authorization_adapter = ActiveAdmin::CanCanAdapter
config.localize_format = :long
end
ability.rb
class Ability
include CanCan::Ability
def initialize(user)
user ||= User.new
if user.admin?
can :read, ActiveAdmin::Page, :name => "Dashboard"
can :manage, :all
elsif user.client?
can :manage, [Act, Do, Fact, Task, T]
cannot :read, ActiveAdmin::Page, :name => "Dashboard"
else
can :read, Activity
end
can :manage, UserSessionsController do |user_session|
user == user_session
end
if user.active?
can :time, Activity
can :read, ActiveAdmin::Page, :name => "Dashboard"
end
can :log_in, User
can :log_out, User
can :reset_password, User
end
end
destroy in sessions controller
def destroy
authorize! :log_out, User
logout
redirect_to root_url, notice: I18n.t('users.log_out')
end
Can anyone point me on how to solve this .... been stuck here for a while ...
cheers
so after investigating further the correct way is
config.logout_link_path = :user_session_path
But sadly ActiveAdmin don't support urls with ids at logout path at the moment.
see this thread from the activeadmin owner
I have customized the form for new/edit to use two column layout for the form fields.
The customization uses formtastic.
Shouldn't the same layout display for "show" by default? Instead I get the activeadmin default one field per row display.
How do I get to display the same layout in "show" as my form (new/edit) pages?
By default the show page has its own layout, so you have to use some css to arrange the inputs, or you can override this method:
https://github.com/activeadmin/activeadmin/blob/master/lib/active_admin/views/components/attributes_table.rb#L22-L43
#collection.each_slice(2) do |records|
td do
content_for(record[0], block || title)
end
td do
content_for(record[1], block || title)
end
end
Or create a new one, and use this in the show block:
module ActiveAdmin
module Views
class AttributesTable < ActiveAdmin::Component
builder_method :attributes_table_for
def row_with_two_fields(*args, &block)
title = args[0]
options = args.extract_options!
classes = [:row]
if options[:class]
classes << options[:class]
elsif title.present?
classes << "row-#{title.to_s.parameterize('_')}"
end
options[:class] = classes.join(' ')
#table << tr(options) do
th do
header_content_for(title)
end
#collection.each_slice(2) do |records|
td do
content_for(record[0], block || title)
end
td do
content_for(record[1], block || title)
end
end
end
end
end
end
Or something similar... I haven't tried it.
I ended up doing the CSS hack
show do
panel "Mandatory Details" do
attributes_table_for contract do
row :account, :class => "column1"
row :customer, :class => "column2"
end
end
panel "Dates And Financials" do
attributes_table_for contract do
row :start_date, :class => "column1"
row :current_end_date, :class => "column2"
row :end_date_w_options, :class => "column1"
end
end
I'm having a small issue manipulating data.
I have a few check-boxes to select various items on the screen, which in turn inputs relevant data such as item name, price, etc. The issue is that these names have to go onto a invoice, and I cannot get the names to transfer onto the invoice nicely.
The invoice has to record the items, but it needs to check to see if a item has been already applied to the invoice and this is what I'm having problems with.
How can I get items to collectively display on a sheet without any additional interactions (I just click the relevant checkbox instead of manually typing it in), and display them nicely.
The items 'Underlay and Extended Warranty' need to be displayed one after another, and not 2-3 boxes away.
Example:
Underlay Extended Warranty
I don't want this:
Underlay
Extended Warranty
Is there a solution to this?
Update:
This happens if I do it the way I know:
I solved this by making a custom Excel VBA Macro that basically tells us the cell that is free which is closest to the top of the invoice:
Public Function GetApplicableCell() As String
Range("C20").Select
If (IsEmpty(Range("'Invoice Sheet'!C20").Value)) Then
GetApplicableCell = "C20"
End If
If (IsEmpty(Range("'Invoice Sheet'!C21").Value)) Then
GetApplicableCell = "C21"
End If
If (IsEmpty(Range("'Invoice Sheet'!C22").Value)) Then
GetApplicableCell = "C22"
End If
If (IsEmpty(Range("'Invoice Sheet'!C23").Value)) Then
GetApplicableCell = "C23"
End If
If (IsEmpty(Range("'Invoice Sheet'!C24").Value)) Then
GetApplicableCell = "C24"
End If
End Function
It can be called by a =GetApplicableCell() from within the worksheet, and we can work with this to produce a workable solution.