活动管理员 rails 操作按钮
Active admin rails action button
我是活跃管理员的新手,使用以下表格
active_admin_form_for resource, :url => account_setup_admin_customer_path(resource), :method => :post, :html => {:class => "new_meeting_search", :id => "meeting_search"} do |f|
f.inputs "Customer Details" do
h2 "Customer Name: #{resource.first_name} #{resource.last_name}"
h2 "Company: #{resource.company_name}"
h2 "Email: #{resource.email}"
f.input :bill_to
f.input :ship_to
f.input :primary_dc, :as => :select, :collection => [["CI - Chambersburg, PA", "CI - Chambersburg, PA"], ["DD - Fort Wayne, IN", "DD - Fort Wayne, IN"], ["EE - Roseburg, OR", "EE - Roseburg, OR"], ["NV - La Vergne, TN", "NV - La Vergne, TN"]]
f.input :secondary_dc, :as => :select, :collection => [["CI - Chambersburg, PA", "CI - Chambersburg, PA"], ["DD - Fort Wayne, IN", "DD - Fort Wayne, IN"], ["EE - Roseburg, OR", "EE - Roseburg, OR"], ["NV - La Vergne, TN", "NV - La Vergne, TN"]]
f.input :ips_primary_dc, :as => :select, :collection => [["CI - Chambersburg, PA", "CI - Chambersburg, PA"], ["DD - Fort Wayne, IN", "DD - Fort Wayne, IN"], ["EE - Roseburg, OR", "EE - Roseburg, OR"], ["NV - La Vergne, TN", "NV - La Vergne, TN"]]
f.input :ips_secondary_dc, :as => :select, :collection => [["CI - Chambersburg, PA", "CI - Chambersburg, PA"], ["DD - Fort Wayne, IN", "DD - Fort Wayne, IN"], ["EE - Roseburg, OR", "EE - Roseburg, OR"], ["NV - La Vergne, TN", "NV - La Vergne, TN"]]
f.input :ipi_account_number
f.input :ipage_username
f.input :ipage_password
f.input :status, :as => :select, :collection => [["Approved", "Approved"], ["Denied", "Denied"]]
f.input :status_comment
end
f.actions
end
我想要单独的操作按钮 "Approve"、"Deny"、"Cancel",而不是状态下拉菜单。我不确定如何以活动形式添加自定义按钮。
你可以放3个链接来模拟。更多详情可以参考AA的表单定制document。
为此,您需要使用 member_action
。
首先,在您的模型中创建一个 public 方法:
model MyModel
#...
def approve
#... any logic here, for example:
update(status: 'Approved')
end
end
然后,在 AA 页面中,您将执行:
action_item only: [:edit] do # or any page, where you need this button
link_to('Approve', the_path_to_aprove(resource), method: :post
end
member_action :approve, method: :post do
if resource.approve
redirect_to somewhere_path, notice: "This have been approved!"
else
redirect_to somewhere_else_path, alert: "Sorry, not all requirements were met for approving"
end
end
end
我是活跃管理员的新手,使用以下表格
active_admin_form_for resource, :url => account_setup_admin_customer_path(resource), :method => :post, :html => {:class => "new_meeting_search", :id => "meeting_search"} do |f|
f.inputs "Customer Details" do
h2 "Customer Name: #{resource.first_name} #{resource.last_name}"
h2 "Company: #{resource.company_name}"
h2 "Email: #{resource.email}"
f.input :bill_to
f.input :ship_to
f.input :primary_dc, :as => :select, :collection => [["CI - Chambersburg, PA", "CI - Chambersburg, PA"], ["DD - Fort Wayne, IN", "DD - Fort Wayne, IN"], ["EE - Roseburg, OR", "EE - Roseburg, OR"], ["NV - La Vergne, TN", "NV - La Vergne, TN"]]
f.input :secondary_dc, :as => :select, :collection => [["CI - Chambersburg, PA", "CI - Chambersburg, PA"], ["DD - Fort Wayne, IN", "DD - Fort Wayne, IN"], ["EE - Roseburg, OR", "EE - Roseburg, OR"], ["NV - La Vergne, TN", "NV - La Vergne, TN"]]
f.input :ips_primary_dc, :as => :select, :collection => [["CI - Chambersburg, PA", "CI - Chambersburg, PA"], ["DD - Fort Wayne, IN", "DD - Fort Wayne, IN"], ["EE - Roseburg, OR", "EE - Roseburg, OR"], ["NV - La Vergne, TN", "NV - La Vergne, TN"]]
f.input :ips_secondary_dc, :as => :select, :collection => [["CI - Chambersburg, PA", "CI - Chambersburg, PA"], ["DD - Fort Wayne, IN", "DD - Fort Wayne, IN"], ["EE - Roseburg, OR", "EE - Roseburg, OR"], ["NV - La Vergne, TN", "NV - La Vergne, TN"]]
f.input :ipi_account_number
f.input :ipage_username
f.input :ipage_password
f.input :status, :as => :select, :collection => [["Approved", "Approved"], ["Denied", "Denied"]]
f.input :status_comment
end
f.actions
end
我想要单独的操作按钮 "Approve"、"Deny"、"Cancel",而不是状态下拉菜单。我不确定如何以活动形式添加自定义按钮。
你可以放3个链接来模拟。更多详情可以参考AA的表单定制document。
为此,您需要使用 member_action
。
首先,在您的模型中创建一个 public 方法:
model MyModel
#...
def approve
#... any logic here, for example:
update(status: 'Approved')
end
end
然后,在 AA 页面中,您将执行:
action_item only: [:edit] do # or any page, where you need this button
link_to('Approve', the_path_to_aprove(resource), method: :post
end
member_action :approve, method: :post do
if resource.approve
redirect_to somewhere_path, notice: "This have been approved!"
else
redirect_to somewhere_else_path, alert: "Sorry, not all requirements were met for approving"
end
end
end