Multistep form with ActiveAdmin?

我与影子孤独终老i 提交于 2019-12-05 02:50:59

问题


Is it possible to create a multistep form with ActiveAdmin?

If not, is it possible to just add another page that it redirects to after submitting the form (one that is not the default index, show or form pages)?


回答1:


I've been fretting with this issue myself. I found that you can add your own pages using collection actions in your ActiveAdmin file. Say your model is called MyModel, you would add this to your ActiveAdmin my_model.rb file.

# GET /admin/my_model/page1
collection_action :page1, :method => :get do
  render 'admin/page1'
end

# POST /admin/my_model/page1
collection_action :page1, :method => :post do
  # Do your form processing
  redirect_to test_admin_my_model_path
end

# GET /admin/my_model/page2
collection_action :page2, :method => :get do
  render 'admin/page2'
end

You would then need to create a view at /app/views/admin/page1.html.erb and page2.html.erb




回答2:


you'll probably want a member action if youre working on a single instance of a model a form would need an action which operates on a single resource

http://activeadmin.info/docs/8-custom-actions.html#member_actions




回答3:


I haven't had to do it within active_admin yet, but I would check out the railscast on multistep forms and combine it with active_admin's collection actions. Essentially, keep it model heavy but have a single custom action that handles the validation, progression, and creation of the model within the form.



来源:https://stackoverflow.com/questions/8080479/multistep-form-with-activeadmin

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!