Hopstream
Hopstream

Reputation: 6451

Multistep form with ActiveAdmin?

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)?

Upvotes: 3

Views: 2877

Answers (3)

ben.m
ben.m

Reputation: 621

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

Upvotes: 1

mnelson
mnelson

Reputation: 3012

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.

Upvotes: 0

Edwin Liang
Edwin Liang

Reputation: 126

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

Upvotes: 5

Related Questions