0

我正在按照A Wicked 示例构建我的向导,除了我首先在专用控制器中创建模型,然后保存重定向到步骤控制器,但我收到一个路由错误说:

No route matches {:action=>"show", :controller=>"needs_personals/steps"}

重定向代码如下所示:

redirect_to needs_personal_step_path, :needs_personal_id => @needsPersonal.id

我使用needs_personal_step_path是因为我的rake routes输出是:

    needs_personal_steps GET    /needs_personals/:needs_personal_id/steps(.:format)          needs_personals/steps#index
                         POST   /needs_personals/:needs_personal_id/steps(.:format)          needs_personals/steps#create
 new_needs_personal_step GET    /needs_personals/:needs_personal_id/steps/new(.:format)      needs_personals/steps#new
edit_needs_personal_step GET    /needs_personals/:needs_personal_id/steps/:id/edit(.:format) needs_personals/steps#edit
     needs_personal_step GET    /needs_personals/:needs_personal_id/steps/:id(.:format)      needs_personals/steps#show
                         PUT    /needs_personals/:needs_personal_id/steps/:id(.:format)      needs_personals/steps#update
                         DELETE /needs_personals/:needs_personal_id/steps/:id(.:format)      needs_personals/steps#destroy

在路由文件中我有这个:

resources :needs_personals do
  resources :steps, controller: 'needs_personals/steps'
end

如果我输入指向浏览器的路径,它就可以工作/needs_personals/90/steps

谢谢。

2012 年 9 月 29 日更新

我相信我已经弄清楚了这样做的原因并实施了解决方法。我认为这是因为与 id 参数混淆而发生的。尽管通过needs_personal_id了,但似乎将 id 视为链接的最后一个参数,而不是中间 id。

我的解决方法只是将它指向实际的字符串 url:

redirect_to "/needs_personals/#{@needsPersonal.id}/steps"

这很好用。虽然很想知道如何以正确的方式做到这一点。

4

1 回答 1

1

我认为这就是你要找的:

redirect_to needs_personals_steps_path(@needsPersonal.id, :first_step)

其中 :first_step 是第一个向导步骤的符号。

于 2012-10-05T19:35:05.530 回答