在过去的 8 年中,我曾尝试使用 Wicked gem 3 次。每一次,我都因为同样的原因放弃了。我再次尝试,因为如果我理解它,我认为它将非常适合我的用例。
我的主要问题是我不明白如何实际启动向导。对于 gem 中使用的示例,它是一个after_registration
已经具有关联user
对象的事件。这没有帮助,我认为该示例对大多数用例也没有帮助。
还有另一个关于Product
在多个步骤中构建 a 的示例。但是,作者未能充分解释路由。来自https://github.com/zombocom/wicked/wiki/Building-Partial-Objects-Step-by-Step:
Since Wicked uses our :id parameter we will need to have a route that also includes :product_id for instance /products/:product_id/build/:id. This is one way to generate that route:
resources :products do
resources :build, controller: 'products/build'
end
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.
好的,我不知道句子的第二部分是什么意思,placeholder product_id
以及/products/building/build
. 我花了 2 个小时尝试,然后转到一个空白的创建表单。
...we can either create this object in another controller and redirect to the wizard
这就是我在成功保存 @product 对象后尝试做的事情。
redirect_to product_by_interchange_path(@product, :step1)
那是行不通的。raise InvalidStepError if the_step.nil?
说我的步数为零。它不是。
redirect_to product_by_interchange_path(@product, step: :step1)
一样。
redirect_to product_by_interchange_path(:step1)
这是 8 年历史的示例应用程序的精确镜像。但当然@product 不在会话变量current_user
中,所以在这种情况下,错误是没有 ID 为 :step1 的产品。
请帮忙!我在这里遗漏了一些非常非常基本的东西,但我非常需要坚持。