邪恶的gemRails – 如何创建一个新的对象
Wicked Gem Wiki上的Building Partial Objects Step by Step页面解释了如何使用wicked
逐步创建对象。
但是如何创建新的Product
对象呢?
我是否必须在ProductsController
的新操作中执行此操作? 我必须在哪里重定向到?
“ 构建部分对象逐步”页面中给出了以下语句。
This also means to get to the create action we don't have a product_id yet so we can either create this object in another controller and redirect to the wizard, or we can use a route with a placeholder product_id such as [POST] /products/building/build in order to hit this create action.
您可以在另一个控制器中创建对象并重定向到向导,或使用带占位符的路径来执行创建操作。
这是我的应用程序中的一个样本,它对我有用
class RegistrationsController < Devise::RegistrationsController protected def after_sign_up_path_for(resource) user_background = resource.build_user_background user_background.save user_background_build_path(user_background.id, :first_step_name) end end
这将创建UserBackground
对象,然后使用新创建的对象id将用户传递到邪恶控制器的第一步。