這是我的第一個Heroku部署,我有一個奇怪的問題,我似乎無法弄清楚。我的應用程序具有嵌套表單,當您創建Product
時,您可以添加Skus
。這一切在Dev中都很有用,但是當部署到Heroku
時,嵌套表單將拒絕Skus
作爲空白。我已經單獨添加了Skus
(Product
表單以外)並且工作正常,另外在Product
表單中嵌套Dimensions
字段可以正確保存。它似乎是它不喜歡的嵌套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
所以我從產品模型和表格中刪除了所有對'Sku'的引用,然後推送到heroku,當我提交時,我仍然收到錯誤'Skus can not be blank'。當我推送到heroku時,有可能我的'product.rb'模型沒有正確更新?我一直在用'git push heroku production_test:master'推動一個主分支,這可能是問題所在嗎? –
我也跑'heroku重啓'無濟於事。 –
我也預先編譯了資產,並確保在部署前確認所有內容。沒有幫助。 –