有问题的问题,刚刚兴起但以前工作过 我得到了这段代码:
控制器
def new
errors ||= Array.new
if params[:file].blank?
errors.push(I18n.t("errors.messages.file_error"))
end
if errors.length == 0
# begin
#
binding.pry
assetObject = Assets.new(:asset=>params[:file])
assetObject.save!
image = assetObject.asset.url(:small)
imageExpBanner = assetObject.asset.url(:expBanner)
data = OpenStruct.new({
id: assetObject.id,
uri: image,
expBannerUri: imageExpBanner
})
@responseObject = OpenStruct.new({
status: true,
errors: [],
code: API_CODE_ERRORS['Services']['Global']['success'],
objectData: data
})
render :template => 'api/v1/general/assets/new' ,:handlers => [:rabl],:formats => [:json]
#rescue => e
# binding.pry
# logger.error e
# errors.push(I18n.t("errors.messages.file_size_error"))
# render :json => Api::Init.ShowErrorJson(API_CODE_ERRORS['Services']['Global']['file_size'],I18n.t("errors.messages.feelike.input_error"), errors).to_json
# end
else
render :json => Api::Init.ShowErrorJson(API_CODE_ERRORS['Services']['Global']['formInputError'],I18n.t("errors.messages.feelike.input_error"), errors).to_json
end
端
模型
类资产<的ActiveRecord ::基
attr_accessible :asset,:asset_content_type, :asset_file_name, :asset_file_size
has_attached_file :asset, :styles => {
:small => "150x150>" ,
:expBanner => "620x184",
:expBigImage => "304X304",
:expSmallImage => "148X148",
:storage => :s3,
:s3_credentials => "#{Rails.root}/config/s3.yml",
:path => "/uploads/:style/:id/:hash.:extension",
:url => :s3_eu_url ,
:hash_secret => "longSecretString"
}
validates :asset, :attachment_presence => true
validates_attachment_size :asset, :less_than => 10.megabytes
validates_attachment_content_type :asset, :content_type => ['image/jpeg','image/gif', 'image/png']
end
现在它给我这个错误:
Started POST "/api/general/assets/new" for 127.0.0.1 at 2013-03-28 11:32:19 +0200
Processing by Api::V1::General::AssetsController#new as JSON
Parameters: {"file"=>#<ActionDispatch::Http::UploadedFile:0x007fc39853ac10 @original_filename="usidentification.jpg", @content_type="image/jpeg", @headers="Content-Disposition: form-data; name=\"file\"; filename=\"usidentification.jpg\"\r\nContent-Type: image/jpeg\r\n", @tempfile=#<File:/tmp/RackMultipart20130328-15640-1hdj5ee>>}
WARNING: Can't verify CSRF token authenticity
Completed 500 Internal Server Error in 3491ms
TypeError - can't dup Symbol:
(gem) paperclip-3.4.0/lib/paperclip/attachment.rb:176:in `block in styles'
(gem) paperclip-3.4.0/lib/paperclip/attachment.rb:175:in `styles'
(gem) paperclip-3.4.0/lib/paperclip/attachment.rb:421:in `post_process_styles'
(gem) paperclip-3.4.0/lib/paperclip/attachment.rb:415:in `block (2 levels) in post_process'
/usr/local/rvm/gems/ruby-1.9.3-p327@global/gems/activesupport-3.2.9/lib/active_support/callbacks.rb:403:in `_run__3148635882202100687__asset_post_process__2098004068316531280__callbacks'
/usr/local/rvm/gems/ruby-1.9.3-p327@global/gems/activesupport-3.2.9/lib/active_support/callbacks.rb:405:in `__run_callback'
/usr/local/rvm/gems/ruby-1.9.3-p327@global/gems/activesupport-3.2.9/lib/active_support/callbacks.rb:385:in `_run_asset_post_process_callbacks'
/usr/local/rvm/gems/ruby-1.9.3-p327@global/gems/activesupport-3.2.9/lib/active_support/callbacks.rb:81:in `run_callbacks'
(gem) paperclip-3.4.0/lib/paperclip/callbacks.rb:26:in `run_paperclip_callbacks'
(gem) paperclip-3.4.0/lib/paperclip/attachment.rb:414:in `block in post_process'
/usr/local/rvm/gems/ruby-1.9.3-p327@global/gems/activesupport-3.2.9/lib/active_support/callbacks.rb:403:in `_run__3148635882202100687__post_process__2098004068316531280__callbacks'
/usr/local/rvm/gems/ruby-1.9.3-p327@global/gems/activesupport-3.2.9/lib/active_support/callbacks.rb:405:in `__run_callback'
/usr/local/rvm/gems/ruby-1.9.3-p327@global/gems/activesupport-3.2.9/lib/active_support/callbacks.rb:385:in `_run_post_process_callbacks'
/usr/local/rvm/gems/ruby-1.9.3-p327@global/gems/activesupport-3.2.9/lib/active_support/callbacks.rb:81:in `run_callbacks'
(gem) paperclip-3.4.0/lib/paperclip/callbacks.rb:26:in `run_paperclip_callbacks'
(gem) paperclip-3.4.0/lib/paperclip/attachment.rb:413:in `post_process'
(gem) paperclip-3.4.0/lib/paperclip/attachment.rb:108:in `assign'
现在是什么剂量意味着TypeError - 不能重复符号 现在我尝试了几种方法来解决这个问题并且每次都需要帮助
答案 0 :(得分:0)
发现问题在那里
has_attached_file :asset, :styles => {
:small => "150x150>" ,
:expBanner => "620x184",
:expBigImage => "304X304",
:expSmallImage => "148X148",
},
:storage => :s3,
:s3_credentials => "#{Rails.root}/config/s3.yml",
:path => "/uploads/:style/:id/:hash.:extension",
:url => :s3_eu_url ,
:hash_secret => "longSecretString"