我在Rails(3.1.1)中使用ActiveAdmin(0.4.0)。如何處理ActiveAdmin中的多個嵌套資源?
我找不到一個很好的方法/破解來處理多個嵌套的資源。
Considerer 3個型號爲:
class Program < ActiveRecord::Base
has_many :knowledges, :dependent => :destroy
end
class Knowledge < ActiveRecord::Base
belongs_to :program
has_many :steps, :dependent => :destroy
end
class Step < ActiveRecord::Base
belongs_to :knowledge
end
而且ActiveAdmin資源:
ActiveAdmin.register Program do
end
ActiveAdmin.register Knowledge do
belongs_to :program
end
ActiveAdmin.register Step do
belongs_to :knowledge
end
在routes.rb中:
namespace :admin do
resources :programs do
resources :knowledges do
resources :steps
end
end
end
這裏的網址,程序的索引,知識和步驟:
http://localhost:3000/admin/programs
http://localhost:3000/admin/programs/1/knowledges
http://localhost:3000/admin/programs/1/knowledges/1/steps
的「知識」管理員,但「步驟」管理員不保持嵌套的情況下沒有問題。
例如,當我使用步驟#索引過濾器我重定向到:
http://localhost:3000/admin/knowledges/1/steps?params ...
但它必須是:
http://localhost:3000/admin/programs/1/knowledges/1/steps?params ...當我創建
同樣的問題新資源:
http://localhost:3000/admin/knowledges/1/steps/new
相反的:
http://localhost:3000/admin/programs/1/knowledges/1/steps/new
相同的p roblem與麪包屑......等等......
我已經在應用/管理/ steps.rb到目前爲止已經試過:
ActiveAdmin.register Step do
belongs_to :knowledge
config.clear_action_items!
action_item :only => :index do
link_to('Create Step', new_admin_program_knowledge_step_path(knowledge.program.id, knowledge.id))
end
index do
column :id
column :knowledge
column :title
column "Actions" do |step|
link_to("Voir", admin_program_knowledge_step_path(step.knowledge.program, step.knowledge, step), :class => "member_link show_link") +\
link_to("Editer", edit_admin_program_knowledge_step_path(step.knowledge.program, step.knowledge, step), :class => "edit_knowledge member_link edit_link", :id => "knowledge_#{dom_id(knowledge)}") +\
link_to("Supprimer", admin_program_knowledge_step_path(step.knowledge.program, step.knowledge, step), :class => "member_link delete_link", :method => :delete, :confirm => "Delete?")
end
end
filter :id
filter :title
filter :subtitle
filter :stage_type
filter :order_by
filter :created_at
filter :updated_at
form :partial => "form"
end
而且在應用程序/視圖/管理/措施/ _form。 html.erb我必須使用activeadmin formbuilder:
<%= semantic_form_for(resource, :url => admin_program_knowledge_steps_path(resource.knowledge.program, resource.knowledge), :builder => ActiveAdmin::FormBuilder) do |f|
f.inputs "Step" do
f.input :knowledge, :as => :hidden
f.form_buffers.last << f.template.content_tag(:li, f.template.content_tag(:label, "Knowledge")+f.template.content_tag(:p, f.object.knowledge.title))
f.input :title
f.input :order_by
end
f.buttons
end %>
嗯......我被困。
如何處理這個很好?任何線索讚賞...
這似乎並不與導軌3.2.6和active_admin 0.4.4 – 2012-06-30 18:37:29
惡劣的工作.. 。也許問Jose Valim有關用新版AA來處理這個問題的正確方法......並在這裏發佈解決方案。 Thx – 2012-07-02 09:06:00
它在最新的'Rails 4.1'和'ActiveAdmin 1.0pre'(來自master)中效果很好。謝謝 :)。 – 2014-08-25 22:10:35