2012-04-29 55 views
0

我已經搜索了很多。 我面對此錯誤 enter image description here使用Carrierwave上傳文件時nil不是符號

在控制器創建方法是

DEF創建 @Category = Category.new(PARAMS [:類別])

respond_to do |format| 
    if @category.save 
    format.html { redirect_to @category, notice: 'Category was successfully created.' } 
    format.json { render json: @category, status: :created, location: @category } 
    else 
    format.html { render action: "new" } 
    format.json { render json: @category.errors, status: :unprocessable_entity } 
    end 
end 
end 

我的形式是

<%= form_for @category, :html => { :multipart => true } do |f| %> 
<% if @category.errors.any? %> 
<div id="error_explanation"> 
    <h2><%= pluralize(@category.errors.count, "error") %> prohibited this category from being saved:</h2> 

    <ul> 
    <% @category.errors.full_messages.each do |msg| %> 
    <li><%= msg %></li> 
    <% end %> 
    </ul> 
    </div> 
    <% end %> 

<div class="field"> 
    <%= f.label :name %><br /> 
    <%= f.text_field :name %> 
</div> 
<div class="field"> 
    <%= f.label :description %><br /> 
    <%= f.text_area :description%> 
</div> 

<div class="field"> 
    <%= f.file_field :image %> 
</div> 

<div class="actions"> 
    <%= f.submit %> 
</div> 
<% end %> 

當我選擇文件上傳並點擊提交按鈕不能繼續

我上傳是

# encoding: utf-8 
require 'carrierwave/processing/rmagick' 
class ImageUploader < CarrierWave::Uploader::Base 

#Include RMagick or MiniMagick support 
include CarrierWave::RMagick 

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

# This is a sensible default for uploaders that are meant to be mounted: 
def store_dir 
"uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}" 
end 

def scale(width, height) 
# do something 
end 

# Create different versions of your uploaded files: 
    version :thumb do 
    process :resize_to_fill => [80, 80] 
    end 

end 
+0

您的CarrierWave上傳類可能有問題(掛載:image屬性)。如果你粘貼你的上傳器的代碼會有幫助。 – Cloudinary

+0

謝謝您的回覆,我已添加上傳者,請指導我,我錯了地方 – ALi

+0

您的上傳者似乎是對的。我們甚至在我們的項目中嘗試過,並且運行良好。您得到的錯誤意味着要運行的給定處理器爲零(而不是:resize_to_fill)。你確定你粘貼的代碼是相關的上傳者造成的問題? – Cloudinary

回答

0

我已創建了新的項目,以同樣的方式和它的工作適用的一切,仍然不知道爲什麼發生這個錯誤,但現在我也沒問題。