Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/cocoa/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 嵌套模型在开发中工作良好,但在生产中无法保存_Ruby On Rails_Heroku_Nested Forms - Fatal编程技术网

Ruby on rails 嵌套模型在开发中工作良好,但在生产中无法保存

Ruby on rails 嵌套模型在开发中工作良好,但在生产中无法保存,ruby-on-rails,heroku,nested-forms,Ruby On Rails,Heroku,Nested Forms,这是我第一次部署Heroku,我有一个奇怪的问题,我似乎无法解决。我的应用程序有一个嵌套表单,当您创建产品时,可以添加SKU。这一切在Dev中都非常有效,但是当部署到Heroku时,嵌套表单拒绝将sku作为空白。我已经单独添加了sku(在产品表单之外),效果很好,另外产品表单中还有嵌套的维度字段,可以正确保存。它似乎只是不喜欢嵌套的sku 奇怪的是,当您提交表单时,日志似乎显示存在sku的嵌套属性 我得到的错误是当表单被回退并说:sku不能为空 另外,我不明白为什么日志文件中的参数被切断,这就是

这是我第一次部署Heroku,我有一个奇怪的问题,我似乎无法解决。我的应用程序有一个嵌套表单,当您创建
产品时,可以添加
SKU
。这一切在Dev中都非常有效,但是当部署到
Heroku
时,嵌套表单拒绝将
sku
作为空白。我已经单独添加了
sku
(在
产品
表单之外),效果很好,另外
产品
表单中还有嵌套的
维度
字段,可以正确保存。它似乎只是不喜欢嵌套的
sku

奇怪的是,当您提交表单时,日志似乎显示存在
sku
的嵌套属性

我得到的错误是当表单被回退并说:
sku不能为空

另外,我不明白为什么日志文件中的
参数被切断,这就是Heroku日志中的显示方式吗

另一件奇怪的事情是,我没有对
Sku
进行任何验证,据我所知,即使
Sku
为空,
产品
也应该能够保存

任何关于故障排除或调查途径的建议都将不胜感激

日志

2013-07-31T21:13:20.977351+00:00 app[web.1]: name: Add Image :: f.object: #<Product:0x007fabc02a7bf0> :: association: images :: container: product-image :: name: Add Image :: f.object: #<Dimension:0x007fabc1dcd6c8> :: association: image :: container: dimension-image-37265 :: name: Add Dimension :: f.object: #<Product:0x007fabc02a7bf0> :: association: dimensions :: container: dimensions :: child_association: image :: name: Add Image :: f.object: #<Dimension:0x007fabc2ea5838> :: association: image :: container: dimension-image-61466 :: name: Add Skus :: f.object: #<Product:0x007fabc02a7bf0> :: association: skus :: container: skus :: child_association: images :: name: Add Images :: f.object: #<Sku:0x007fabc305cde8> :: association: images :: container: sku-image-4581 :: Processing by ProductsController#create as HTML
2013-07-31T21:13:20.977351+00:00 app[web.1]: che"=>"", "_destroy"=>"false"}}}}}, "commit"=>"Save"}
2013-07-31T21:13:20.977351+00:00 app[web.1]:   Rendered components/_component_select.html.haml (5.5ms)
2013-07-31T21:13:20.977351+00:00 app[web.1]:   Rendered components/_component_select.html.haml (3.3ms)
2013-07-31T21:13:20.977351+00:00 app[web.1]:   Rendered components/_component_select.html.haml (2.5ms)
2013-07-31T21:13:20.977351+00:00 app[web.1]:   Parameters: {"utf8"=>"✓", "authenticity_token"=>"Y7OmGrfxdBRE2zw63voqpP8j/W9SYJFGcSphzhpPJeQ=", "product"=>{"active"=>"1", "shown"=>"1", "skin_id"=>"2", "collection_id"=>"1", "component_ids"=>["9"], "title"=>"test", "images_attributes"=>{"0"=>{"asset_cache"=>"", "_destroy"=>"false"}}, "features"=>"<p>test</p>\r\n", "dimensions_attributes"=>{"0"=>{"_destroy"=>"false", "title"=>"Overall Dimensions", "width"=>"1", "height"=>"1", "depth"=>"1", "image_attributes"=>{"0"=>{"asset_cache"=>"", "_destroy"=>"false"}}}}, "video"=>"", "skus_attributes"=>{"0"=>{"_destroy"=>"false", "finish_id"=>"1", "title"=>"lskdjf", "images_attributes"=>{"0"=>{"asset"=>#<ActionDispatch::Http::UploadedFile:0x007fabc014dcf0 @original_filename="albino stallion.jpg", @content_type="image/jpeg", @headers="Content-Disposition: form-data; name=\"product[skus_attributes][0][images_attributes][0][asset]\"; filename=\"albino stallion.jpg\"\r\nContent-Type: image/jpeg\r\n", @tempfile=#<Tempfile:/tmp/RackMultipart20130731-2-1n97ibo>>, "asset_ca
2013-07-31T21:13:20.977351+00:00 app[web.1]:   Rendered components/_component_select.html.haml (3.1ms)
2013-07-31T21:13:20.977351+00:00应用程序[网站1]:名称:添加图像::f.object:#::关联:图像::容器:产品图像::名称:添加图像::f.object:#::关联:图像::容器:维度-Image-37265::名称:添加维度::f.object:#:::关联:维度::容器:维度::子对象关联:图像::名称:添加图像::f.object:#:关联:图像::container:dimension-image-61466::name:Add-sku::f.object:#::关联:Skus::container:Skus::child_关联:images::name:Add-images::f.object:#::关联:images::container:sku-image-4581::products控制器处理#创建为HTML
2013-07-31T21:13:20.977351+00:00应用程序[web.1]:che“=>”,“\u destroy”=>“false”},,“commit”=>“Save”}
2013-07-31T21:13:20.977351+00:00应用程序[web.1]:渲染组件/_component_select.html.haml(5.5ms)
2013-07-31T21:13:20.977351+00:00应用程序[web.1]:渲染组件/_component_select.html.haml(3.3ms)
2013-07-31T21:13:20.977351+00:00应用程序[web.1]:渲染组件/_component_select.html.haml(2.5ms)
2013-07-31T21:13:20.977351+00:00应用程序[web.1]:参数:{“utf8”=>“✓“,”真实性令牌“=>”Y7OmGrfxdBRE2zw63voqpP8j/W9SYJFGcSphzhpPJeQ=“,”产品“=>”活动“=>”1“,”显示“=>”1“,”皮肤id“=>”2“,”集合id“=>”1“,”组件id“=>”,”标题“=>”测试“,”图像属性“=>”{0”=>,”资产缓存“,”销毁“=>,”假“,”特征“=>,”测试“,”假属性“,”销毁“,”0”{>标题“=>”外形尺寸“=>”宽度“=>”1“,”高度“=>”1“,”深度“=>”1“,”图像属性“=>”{“0”=>{“资产缓存”=>”,”图像销毁“=>”假”=>,“SKU属性”=>{“0”=>{“资产销毁”=>“假”;“完成id”=>“1”,“标题”=>“lskdjf”,“图像属性”=>{“0”=>,“资产”=>,“资产ca”
2013-07-31T21:13:20.977351+00:00应用程序[web.1]:渲染组件/_component_select.html.haml(3.1ms)
Product.rb

class Product < ActiveRecord::Base
  include Rails.application.routes.url_helpers

  default_scope order('products.id ASC')

  attr_accessible               :name, 
                                :title,
                                :features, 
                                :active,
                                :shown,
                                :video,

                                ## belongs_to ##
                                :collection_id,
                                :skin_id,

                                ## has_many ##
                                :component_ids,

                                ## nested attributes ##
                                :skus_attributes,
                                :dimensions_attributes,
                                :images_attributes


  belongs_to                    :component
  belongs_to                    :collection
  belongs_to                    :skin

  has_many                      :product_compilation_components,    :dependent  => :destroy
  has_many                      :components,                        :through    => :product_compilation_components

  has_many                      :dimensions, dependent: :destroy
  accepts_nested_attributes_for :dimensions, reject_if: lambda { |a| a[:width].blank? || a[:height].blank? || a[:depth].blank? }, allow_destroy: true

  has_many                      :skus, dependent: :destroy
  accepts_nested_attributes_for :skus

  has_many                      :images, as: :imageable, dependent: :destroy
  accepts_nested_attributes_for :images, reject_if: proc { |attrs| attrs['asset'].blank? && attrs['asset_cache'].blank? }, allow_destroy: true

  validates_presence_of         :title
  validates_presence_of         :collection
  validates_presence_of         :skin

  before_save                   :create_name

  def show
    if self.active && self.shown
      return true
    end

    return false
  end

  def path(sku = skus.first)
    return product_sku_path(id, sku.id)
  end

  def categories
    @category_ids = collection.components.map{ |component| component.category_id }
    @categories = Category.all(:conditions => { :id => @category_ids })
    return @categories
  end 

  def brands
    @brand_ids = collection.styles.map{|style| style.brand_id}
    @brands = Brand.all(:conditions => { :id => @brand_ids })
    return @brands
  end

  def self.skus_by_finish(finish_id)
    @skus = Sku.where(:finish_id => finish_id);
    return @skus
  end

  private

  def create_name
    self.name = title.parameterize
  end
end
类产品:销毁
有多个:组件,:到=>:产品\u编译\u组件
有很多:维度,依赖::销毁
接受:维度的_嵌套_属性_,如果:lambda{a | a[:宽度]则拒绝_。空白?| a[:高度)。空白?| a[:深度)。空白?},允许_销毁:真
有多个:SKU、从属::销毁
接受:SKU的\u嵌套\u属性\u
有很多:映像,如::可映像,依赖::销毁
接受_嵌套的_属性_for:images,拒绝_如果:proc{| attrs | attrs['asset'].blank?&&attrs['asset_cache'].blank?},允许_销毁:true
验证是否存在:title
验证是否存在:集合
验证是否存在:皮肤
保存前:创建\u名称
def秀
如果显示self.active&&self
返回真值
结束
返回错误
结束
def路径(sku=sku.first)
退货产品库存路径(id,sku.id)
结束
def类别
@category_id=collection.components.map{| component | component.category_id}
@categories=Category.all(:条件=>{:id=>@Category\u id})
返回@categories
结束
def品牌
@brand|id=collection.styles.map{| style | style.brand|id}
@brands=Brand.all(:条件=>{:id=>@Brand_id})
返回@品牌
结束
定义自身SKU由完成(完成id)
@Sku=Sku.where(:finish\u id=>finish\u id);
返回@SKU
结束
私有的
def创建_名称
self.name=title.parameterize
结束
结束

所以我不能100%确定问题出在哪里,但我已经解决了