2012-10-12 37 views
3

我使用邪惡的寶石來建立一個表單嚮導。在文檔中,它使用current_user對象,但我想使用不同的對象。我努力向redirect_to添加一個參數,以便我可以使用這個對象。Rails邪惡的寶石與params重定向

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 

如何在文檔中使用的特定對象邪惡的寶石是這樣,而不是CURRENT_USER例子嗎?

+0

您可以張貼在你是怎麼做到的解決方案? – kishanio

回答

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 
0

嚮導寶石需要:id參數作爲步驟名稱。所以你不應該通過:id作爲參數,因爲它會與步驟名稱衝突。

products_controller.rb

redirect_to product_step_path(product_id: @product.id) 

product_steps_controller.rb

@product = Product.find(params[:product_id]) 
相關問題