lundi 23 mars 2015

Activeadmin: using a form in the show section

My app collects information from an outside system about things (we call these things "nodes"), and shows them to the user. The user cannot edit nodes directly - updating the app's database doesn't magically change the outside system, of course - but they can issue commands that do things to the outside system.


I would like to give users a drop-down list of actions, so they can look at a particular node, select the action they want, and kick off a script that does that action to that node.


I have a form block like this, in app/admin/nodes.rb:



ActiveAdmin.register Node do
...
form do |f|
inputs 'Details' do
input :contact, :as => :select, :collection => ["Action A", "Action B", "Action C"]
end
actions
end


(:contact is a random field in the node record. "input" insisted that I give it something...)


If I put this block at the same level as the index and show blocks, then


"/admin/nodes/22" doesn't show it at all.


"/admin/nodes/22/edit" does show it and it works OK.


I'd rather have the form's drop-down actions displayed at "/admin/nodes/22", but when it move the form block into the "show" section, /admin/nodes/22 gives me "undefined method `inputs'". Maybe that's just how ActiveAdmin works: I have to use /admin/nodes/22/edit to display the form. OK, I can live with that.


But I also want the user to be able to add comments to the node. When I put "active_admin_comments" in the form like this:



form do |f|
inputs 'Details' do
input :contact, :as => :select, :collection => ["Action A", "Action B", "Action C"]
end
active_admin_comments
end


Then /admin/nodes/22/edit gives me "undefined local variable active_admin_comments".


So I can get the comments to work with /admin/nodes/22; I can get the form and drop-down to work with /admin/nodes/22/edit; but I can't get them both to work on the same page.


Should I just try a different way to give the user a choice of actions?


Aucun commentaire:

Enregistrer un commentaire