gpt4 book ai didi

ruby-on-rails - "stack level too deep"处理嵌套形式的载波图像版本时

转载 作者:行者123 更新时间:2023-12-03 00:00:36 24 4
gpt4 key购买 nike

这是一个奇怪的问题,不幸的是,它有很多潜在的来源。我正在使用 Carrierwave 和 Cocoon Gems 来帮助嵌套文件上传。我在 uploader 中执行的任何类型的版本处理都会导致堆栈级别太深错误。如果我删除处理,它会正常保存嵌套图像。我尝试进行了很多故障排除,并将范围缩小到了这一点;例如,如果我仅删除版本处理,则它可以正常工作。如果我删除除版本处理之外的所有内容,它会引发相同的错误。有很多潜在的来源,所以这里有一些代码:

父表单(截断)

<%= semantic_form_for [@object, @discussion], multipart: true , input_html: {class: "form-horizontal"} do |f| %>
<div id="pictures">
<%= f.semantic_fields_for :pictures do |p| %>
<%= render 'picture_fields', :f => p %>
<% end %>
<div class="links">
<%= link_to_add_association f, :pictures do %>
<button type="button" class="btn btn-success btn-sm">Add Image</button>
<% end %>
</div>
</div>
<% end %>

嵌套形式

<div class="nested-fields">
<div class="row">
<div class="col-md-10">
<%= f.input :pic, label: false %>
<%= f.input :pic_cache, as: :hidden %>
</div>
<div class="col-md-2 pull-right">
<%= link_to_remove_association f do %>
<button type="button" class="btn btn-danger btn-sm">REMOVE</button>
<% end %>
</div>
</div>
</div>

上传者

        # encoding: utf-8

class ImageUploader < CarrierWave::Uploader::Base

# Include RMagick or MiniMagick support:
include CarrierWave::RMagick
# include CarrierWave::MiniMagick

# Include the Sprockets helpers for Rails 3.1+ asset pipeline compatibility:
# include Sprockets::Helpers::RailsHelper
# include Sprockets::Helpers::IsolatedHelper

# Choose what kind of storage to use for this uploader:
# storage :file
# storage :fog

# Override the directory where uploaded files will be stored.
# This is a sensible default for uploaders that are meant to be mounted:
def store_dir
if Rails.env.test?
"uploads/test/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
else
"uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
end
end

#custom method to access local files as full paths
def local_path_or_remote_url
if CarrierWave::Uploader::Base.storage.to_s == CarrierWave::Uploader::Base.storage_engines[:file]
path
else
url
end
end

# Process files as they are uploaded:
# process :scale => [200, 300]
#
# def scale(width, height)
# # do something
# end

# Create different versions of your uploaded files:
process :resize_to_fit => [400, 400]

version :thumb do
process :resize_to_fill => [72, 72]
end


# Add a white list of extensions which are allowed to be uploaded.
# For images you might use something like this:
def extension_white_list
%w(jpg jpeg gif png)
end

# Override the filename of the uploaded files:
# Avoid using model.id or version_name here, see uploader/store.rb for details.
def filename
"pic#{File.extname(original_filename).downcase}" if original_filename
end

end

我的上传者使用基本相同的代码,没有任何问题。仅当嵌套时,该版本控制代码才会出现问题。我知道这可能有很多潜在的来源。有什么想法吗?

最佳答案

这对我有用。

gem 'rmagick', :require => 'RMagick'

关于ruby-on-rails - "stack level too deep"处理嵌套形式的载波图像版本时,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18774686/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com