Is there any way of using ActiveAdmin's form dsl from a custom member action?
I want to retain the has_many
semantic to avoid having to implement it myself from scratch, but I want a separate form view.
Something like this would be ideal:
member_action :subject, method: :get do
@subject = Subject.find(params[:id])
form do |f|
f.inputs do
f.input :name, :required => true, :input_html => {:class => "large"}
end
end
end
Arbre doesn't seem to support formtastic, so I wasn't able to get a form to work in a .arb
file. You can use formtastic in a .erb
file however. So while it is not using ActiveAdmin's DSL wrapper for formtastic, the syntax is similar:
# app/admin/foo.rb
ActiveAdmin.register Foo do
member_action :subject, method: [:get, :patch] do
if request.get?
render :some_custom_view
else
# handle update or whatever else you would like to do on form submit
# if resource.update(...)
# redirect_to ...
# else
# render :some_custom_view
# end
end
end
end
# app/views/admin/foo/some_custom_view.html.erb
<%= semantic_form_for [:admin, resource], url: subject_admin_foo_path(resource) do |f| %>
<%= f.semantic_errors(*f.object.errors.keys) %>
<%= f.inputs do %>
<%= f.input :name %>
<% end %>
<%= f.actions %>
<% end %>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With