简体   繁体   English

邪恶宝石的轨道。 数据不会更新

[英]Rails with Wicked gem. Data will not update

I am using the Wicked gem to create an object in multiple steps. 我正在使用Wicked gem在多个步骤中创建对象。 Everything seemed to be working fine until I realized that the data was not saving. 在我意识到数据没有保存之前,一切似乎都工作正常。 I noticed it was not saving whenever url: wizard_path was present in the form builder. 我注意到,每当表单构建器中出现url: wizard_path时,它都不会保存。 When that is not there, the data saves just fine, no matter which step I am on. 如果不存在该数据,则无论我在哪一步,数据都可以很好地保存。 This is what my controller for the object builder looks like: 这是我的对象生成器控制器如下所示:

class Bids::BuildController < ApplicationController
  include Wicked::Wizard

  steps :intro, :problems, :solutions, :pricing

  def show
    @bid = Bid.find(params[:bid_id])
    render_wizard
  end

  def create
    @bid = Bid.new(bid_params)
    redirect_to wizard_path(steps.first, :bid_id => @bid.id)
  end

  def update
    @bid = Bid.find(params[:bid_id])
    params[:bid][:status] = 'active' if step == steps.last
    @bid.attributes = params[:bid].permit(:bid_attribute)
    render_wizard @bid
  end

  # GET /bids/new
  def new
    @bid = Bid.new
    redirect_to wizard_path(steps.first, :bid_id => @bid.id)
  end

end

You mentioned in your comment that you are permitting params in the bid controller. 您在评论中提到您正在允许出价控制器中的参数。 Add them to your build controller. 将它们添加到您的构建控制器。 Since you are building your object in this controller, it needs to have access to the permitted params. 由于要在此控制器中构建对象,因此它需要有权访问允许的参数。

Add: 加:

def build_params
  params.require(:bid).permit(:param_1,:param_2,:param_3,:etc)
end

to your bids/build_controller.rb 到您的bids/build_controller.rb

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM