这是我的第一次Heroku部署,我有一个奇怪的问题,我似乎无法弄清楚。我的应用有一个嵌套表单,当您创建Product
时,您可以添加Skus
。这一切在Dev中都很有用,但是当部署到Heroku
时,嵌套表单会将Skus
拒绝为空白。我已单独添加Skus
(Product
表单之外)并且工作正常,此外还有Dimensions
表单中的嵌套Product
字段可以正常保存。它似乎是它不喜欢的嵌套Skus
。
奇怪的是,日志似乎表明在提交表单时Skus
存在嵌套属性。
我得到的错误是表单被踢回来并说:Skus can't be blank
另外,我不明白为什么在Parameters
被截断的日志文件中,它是如何在Heroku日志中显示的?
关于这一点的另一个奇怪的事情是我没有对Skus
进行任何验证,据我所知Product
即使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)
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
答案 0 :(得分:0)
所以我不是100%确定问题是什么,但我已经解决了。我最终删除了任何与skus有关的东西,然后慢慢地将它逐渐添加回来。
我认为最有可能导致这个问题的是我有一个我重命名的Product
类的版本,因为我没有使用它,并且不想忘记我的工作完成(我知道,没必要,因为我正在使用git。我猜老习惯很难)无论如何,我已经改变了文件名,但是我忽略了重命名文件中的类定义。这个名字是在我使用的真实Product
课程之后。我认为这导致了heroku的冲突。我不明白的是为什么它在我的本地开发环境中没有引起任何问题。