自定义控制器动作的Wicked :: Wizard :: InvalidStepError

时间:2018-12-03 19:20:01

标签: ruby-on-rails wicked-gem

我的步骤控制器中有一个自定义操作,该操作会基于选择内容(后台有一些js)更新html选择,这是该操作...

class CarStepsController < ApplicationController
  include Wicked::Wizard

  skip_before_action :setup_wizard, only: [:update_make]
  before_action :logged_in_user

  steps :parts, :accessories

  def show
    @car = Car.find(params[:car_id])
    case step
    when :parts
      @vehicles = @car.vehicles.build
      @years = Vicc.select("distinct model_year").order("model_year DESC")
      @makes = Vicc.where("model_year = ?", '1980')
    when :accessories
      @accessories = @car.accessories.build
    end
    render_wizard
  end

  def update
    @car = Car.find(params[:car_id])
    @car.update_attributes(permitted_params)
    render_wizard @car
  end

  def update_make # THIS IS WHERE IT ERRORS.
    byebug
    @makes = ViccInformation.where("model_year = ?", params[:model_year])
    respond_to do |format|
      format.js
    end
  end
end

在我的路线中,我有这个:

scope "cars/:id" do
  resources :car_steps
  get 'cars/update_make', as: 'update_make'
end

这是执行ajax调用的js:

  $(document).change(function () {
    console.log($("#years_select option:selected").val());
    console.log($("#car_id").val());
    $.ajax({
      url: "update_make",
      type: 'GET',
      dataType: 'script',
      data: {
        model_year: $("#years_select option:selected").val()
      },
      success: function (data) {
        console.log("success");
      },
      error: function (err) {
        console.log("err", err);
      },
    });
  });

选择选项时出现错误:Wicked::Wizard::InvalidStepError (The requested step did not match any steps defined for this controller.):。谷歌搜索之后,我发现您需要在控制器中添加skip_before_action :setup_wizard, only: [:update_make]才能告诉邪恶的宝石在向导中忽略此操作,我做到了。

但是我仍然收到错误:Wicked::Wizard::InvalidStepError (The requested step did not match any steps defined for this controller.):

这是完整的控制台输出:

Started GET "/cars/6/car_steps/update_make?model_year=2011&_=1543867316050" for 127.0.0.1 at 2018-12-03 15:02:07 -0500
Processing by CarStepsController#show as JS
  Parameters: {"model_year"=>"2011", "_"=>"1543867316050", "car_id"=>"6", "id"=>"update_make"}
Completed 500 Internal Server Error in 0ms (ActiveRecord: 0.0ms)

关于如何解决此问题的任何建议?

0 个答案:

没有答案