0

这是我的第一次 Heroku 部署,我遇到了一个我似乎无法弄清楚的奇怪问题。我的应用程序有一个嵌套表单,当您创建一个Product您可以添加Skus. 这一切在 Dev 中都很好用,但是当部署到Heroku嵌套表单时会拒绝Skusas 空白。我已经Skus单独添加(在Product表单之外)并且效果很好,此外表单中还有嵌套Dimensions字段Product可以正确保存。它似乎只是Skus它不喜欢的嵌套。

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

我得到的错误是表单被踢回来并说:Skus can't be blank

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

另一个奇怪的事情是我没有任何验证Skus,据我所知Product,即使 aSku为空白,a 也应该能够被保存。

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

日志

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)

产品.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
4

1 回答 1

0

所以我不是 100% 确定问题是什么,但我已经解决了。我最终删除了与 skus 相关的所有内容,然后一点一点地慢慢将其添加回来。

我认为最有可能导致问题的是我有一个Product我重命名的类的版本,因为我没有使用它并且不想忘记我所做的工作(我知道,没有必要,因为我正在使用 git。我想旧习惯很难改掉)无论如何,我已经更改了文件名,但是我忽略了重命名文件中的类定义。这个名字是在Product我使用的真实课程之后出现的。我认为这引起了heroku的冲突。我不明白的是为什么它在我的本地开发环境中没有引起任何问题。

于 2013-08-01T19:06:44.177 回答