使用Carrierwave上传文件时,nil不是符号

时间:2012-04-29 21:16:29

标签: ruby-on-rails-3 carrierwave

我搜索了很多。 我正面临这个错误 enter image description here

Controller中的创建方法是

def创建     @category = Category.new(params [:category])

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

1 个答案:

答案 0 :(得分:0)

我有创建新项目,以相同的方式应用所有内容及其工作,仍然不知道为什么会出现此错误,但现在我没有问题。