Wicked向导gem忽略了我的步骤并跳转到request_steps / wicked_finish

时间:2013-09-23 14:19:28

标签: ruby ruby-on-rails-4 wicked-gem

我正在使用wicked gem 在我点击RequestStepsController#update之后,我被重定向到/ request_steps / wicked_finish。我不知道为什么。有什么建议? 如果它按照我的预期工作,那么更新对象后的下一步将是:the_frame,如步骤中所述。

来自日志:

  Started PUT "/request_steps/77" for 127.0.0.1

  Processing by RequestStepsController#update as HTML
    Parameters: {"utf8"=>"✓", "authenticity_token"=>"XXX", "request"=>{"background_information"=>"prefilled"}, "commit"=>"C
  7"}

  Redirected to http://localhost:3000/request_steps/wicked_finish

  Started GET "/request_steps/wicked_finish" for 127.0.0.1
  Processing by RequestStepsController#show as HTML
    Parameters: {"id"=>"wicked_finish"}
  Completed 404 Not Found in 180ms

  ActiveRecord::RecordNotFound - Couldn't find Request without an ID:

这是我的RequestStepsController

class RequestStepsController< ApplicationController的     包括Wicked :: Wizard

steps :background_information, 
  :no_list_what_can_go_wrong,
  :the_frame,
  :select_group


def show
  @request = Request.find(params[:request])
  render_wizard
end

def update
  @request = Request.find(params[:id])
  @request.update_attributes(request_params)
  render_wizard @request
end

def request_params
  params.require(:request).permit(:title, :description, :goal, 
     :request_group_id, 
     :repository_url,
    :background_information
    )
end

这是我的表格:

= simple_form_for(@request, url: wizard_path(@request), method: :put, :html => { :class => 'form-inline span8 help_text' }) do |f|

1 个答案:

答案 0 :(得分:4)

(免责声明:我没有读完你的完整问题:))

render_wizard方法检查它是否可以保存您的@request对象。如果它可以它将进入下一步并尝试将其保存在那里......依此类推......直到最后一步。

请在此处查看源代码:https://github.com/schneems/wicked/blob/master/lib/wicked/controller/concerns/render_redirect.rb#L17

要阻止它这样做,您需要确保在特定步骤中无法保存您的对象。类似于此处描述的内容:https://github.com/schneems/wicked/wiki/Building-Partial-Objects-Step-by-Step

您也可以使用render_step(params[:id])代替render_wizard