问题描述
我正在使用 wicked gem 构建表单向导.在文档中,它使用的是 current_user 对象,但我想使用不同的对象.我正在努力向 redirect_to 添加一个参数,以便我可以使用这个对象.
I am using the wicked gem to build a form wizard. In the documentation, it is using the current_user object but I want to use a different object. I am struggling with adding a parameter to redirect_to so I can use this object.
products_controller.rb
def create
@product = current_user.product.build(params[:product])
@product.ip_address = request.remote_ip
if @product.save
redirect_to product_steps_path # This is where I think I need to pass product object but not sure how
else
render 'new'
end
end
product_steps_controller.rb
class ProductStepsController < ApplicationController
include Wicked::Wizard
steps :apps, :templates
def show
@product = Product.find(params[:id])
render_wizard
end
end
路线:
resources :products
resources :product_steps
我用上面的代码得到的错误是:
The error I get with the above code is:
ActiveRecord::RecordNotFound in ProductStepsController#show
Couldn't find Product with id=apps
如何在这样的特定对象上使用 wicked gem 而不是文档中的 current_user 示例?
How do I use the wicked gem on a specific object like this instead of the current_user example in the documentation?
推荐答案
这就是我的工作.
products_controller.rb
products_controller.rb
if @product.save
redirect_to product_step_path(:id => "apps", : product_id => @ product.id)
else
...
product_steps_controller.rb
product_steps_controller.rb
def show
@asset = Asset.find(params[:asset_id])
render_wizard
end
这篇关于Rails 邪恶的宝石重定向与参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!