2013-03-28 50 views
0

有代碼的問題是剛剛興起,但現在 我得到這個代碼之前工作:錯誤紅寶石 - 代碼「類型錯誤不能DUP符號」

  1. 控制器

    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 
    

  2. 模型

類資產<的ActiveRecord :: Base的

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/[email protected]/gems/activesupport-3.2.9/lib/active_support/callbacks.rb:403:in `_run__3148635882202100687__asset_post_process__2098004068316531280__callbacks' 
    /usr/local/rvm/gems/[email protected]/gems/activesupport-3.2.9/lib/active_support/callbacks.rb:405:in `__run_callback' 
    /usr/local/rvm/gems/[email protected]/gems/activesupport-3.2.9/lib/active_support/callbacks.rb:385:in `_run_asset_post_process_callbacks' 
    /usr/local/rvm/gems/[email protected]/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/[email protected]/gems/activesupport-3.2.9/lib/active_support/callbacks.rb:403:in `_run__3148635882202100687__post_process__2098004068316531280__callbacks' 
    /usr/local/rvm/gems/[email protected]/gems/activesupport-3.2.9/lib/active_support/callbacks.rb:405:in `__run_callback' 
    /usr/local/rvm/gems/[email protected]/gems/activesupport-3.2.9/lib/active_support/callbacks.rb:385:in `_run_post_process_callbacks' 
    /usr/local/rvm/gems/[email protected]/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' 

現在什麼劑量它意味着類型錯誤 - 不能DUP符號 現在我嘗試幾種方法解決在而得到這個每次都需要在這個

+0

請你也可以發佈你的代碼與'has_attached_file'部分的代碼綁定 – Aleks 2013-03-28 09:41:11

回答

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"