Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ruby-on-rails-3/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 3 使用Carrierwave上载文件时,nil不是符号_Ruby On Rails 3_Carrierwave - Fatal编程技术网

Ruby on rails 3 使用Carrierwave上载文件时,nil不是符号

Ruby on rails 3 使用Carrierwave上载文件时,nil不是符号,ruby-on-rails-3,carrierwave,Ruby On Rails 3,Carrierwave,我找了很多。 我面临着这个错误 控制器中的Create方法为 def创建 @类别=类别。新参数[:类别] respond_to do |format| if @category.save format.html { redirect_to @category, notice: 'Category was successfully created.' } format.json { render json: @category, status: :created, locat

我找了很多。 我面临着这个错误

控制器中的Create方法为

def创建 @类别=类别。新参数[:类别]

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

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

您的CarrierWave uploader类可能有问题,该类装载了:image属性。这将有助于你粘贴代码的上传者。感谢回应,我已经添加了上传者,请告诉我哪里我错了你的上传者似乎是正确的。实际上,我们甚至在我们的项目中进行了尝试,效果很好。您得到的错误意味着要运行的给定处理器是nil,而不是:resize_to_fill。您确定粘贴的代码是导致问题的相关上传程序的代码吗?