使用 ActiveAdmin 进行多步骤表单?

发布于 2024-12-14 21:23:57 字数 87 浏览 2 评论 0原文

是否可以使用 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)?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

以酷 2024-12-21 21:23:57

我自己也一直在苦恼这个问题。我发现您可以使用 ActiveAdmin 文件中的集合操作添加自己的页面。假设您的模型名为 MyModel,您可以将其添加到 ActiveAdmin my_model.rb 文件中。

# 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

然后,您需要在 /app/views/admin/page1.html.erb 和 page2.html.erb 创建一个视图

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

许久 2024-12-21 21:23:57

如果您正在处理模型的单个实例,您可能需要成员操作
表单需要对单个资源进行操作

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

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

夏日浅笑〃 2024-12-21 21:23:57

我还没有在 active_admin 中执行此操作,但我会查看多步表单上的railscast< /a> 并将其与 active_admin 的 集合操作。本质上,保持模型重,但有一个自定义操作来处理表单内模型的验证、进展和创建。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文