3

我正在使用 wicked gem 来构建表单向导。在文档中,它使用 current_user 对象,但我想使用不同的对象。我正在努力向 redirect_to 添加一个参数,以便我可以使用这个对象。

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

我用上面的代码得到的错误是:

ActiveRecord::RecordNotFound in ProductStepsController#show

Couldn't find Product with id=apps

如何在这样的特定对象上使用 wicked gem 而不是文档中的 current_user 示例?

4

2 回答 2

5

这就是我要工作的。

products_controller.rb

if @product.save
  redirect_to product_step_path(:id => "apps", : product_id => @ product.id)
else
...

product_steps_controller.rb

def show
  @asset = Asset.find(params[:asset_id])
  render_wizard
end
于 2012-11-26T23:27:40.113 回答
0

向导 gem 将:id参数作为步骤名称。所以你不应该:id作为参数传递,因为它会与步骤名称冲突。

products_controller.rb

redirect_to product_step_path(product_id: @product.id)

product_steps_controller.rb

@product = Product.find(params[:product_id])
于 2016-02-18T06:11:56.683 回答