【问题标题】:Rails create object params nullRails 创建对象参数 null
【发布时间】:2017-07-31 10:22:11
【问题描述】:

创建产品并使用 wicked gem 更新日志正在吐出的对象后

在重定向到参数变为空的步骤。有人知道为什么吗?

[object Object]

HTTP_REFERER    http://localhost:3000/products/new?
params  null
utf8    ✓


def create
    @product = current_user.products.build(params[:product])
    if @product.save

      redirect_to product_step_path(@product, Product.form_steps.first, only_path: true, format: :html)

    else
      render :new, format: :html
    end
  end

class Product::StepsController < ApplicationController
  include Wicked::Wizard
  steps *Product.form_steps

  def show
    @product = Product.find(params[:product_id])

    render_wizard 
   end
end

【问题讨论】:

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


    【解决方案1】:

    在重定向到参数变为空的步骤。有人知道为什么吗?

    是的。因为你告诉它这样做。

      redirect_to product_step_path(@product, Product.form_steps.first, only_path: true, format: :html)
    

    您将进入一个带有新参数的新页面。如果您希望当前请求的某些参数在此下一个请求中可用,请在redirect_to 中指定它们。

    【讨论】:

    • 谢谢@SergioTulentsev,但尚未指定 redirect_to product_step_path(@product, Product.form_steps.first, only_path: true, format: :html)?我如何指定?
    • @japalow:类似这样的:redirect_to product_step_path(@product, Product.form_steps.first, only_path: true, format: :html, foobar: params[:foobar])
    猜你喜欢
    • 2017-01-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-11-15
    • 1970-01-01
    • 1970-01-01
    • 2016-01-12
    相关资源
    最近更新 更多