在生产中为 rails 使用回形针插件时出错.图像未保存到服务器 [英] Errors when using paperclip plugin for rails in production. Image not being saved to server

查看:26
本文介绍了在生产中为 rails 使用回形针插件时出错.图像未保存到服务器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在运行 rails 3 和 paperclip 2.3.4.在 OS X 上的开发中,一切都运行良好,但在生产中存在一些我无法弄清楚的问题.如果有人有任何建议,请告诉我.

I am running rails 3 and paperclip 2.3.4. In development on OS X every thing runs great but production there are some issues that I can't quite figure out. If anyone have suggestions please let me know.

我正在使用 Flash BTW 上传文件.就像我说的本地开发效果很好.

I am uploading the file using flash BTW. Like I said local development works great.

我检查了生产日志,看起来 POST 发生得很好.

I checked the production log and it looks like the POST is happening just fine.

Started POST "/addimage" for 10.0.136.119 at 2011-01-13 19:49:09 +0000
  Processing by BowlsController#create as HTML
  Parameters: {"Filename"=>"IMG_0585.JPG", "fbid"=>"123456789", "Filedata"=>#<ActionDispatch::Http::UploadedFile:0x000000054afdf8 @original_filename="IMG_0585.JPG", @content_type="application/octet-stream", @headers="Content-Disposition: form-data; name=\"Filedata\"; filename=\"IMG_0585.JPG\"\r\nContent-Type: application/octet-stream\r\n", @tempfile=#<File:/tmp/RackMultipart20110113-23741-bhze8q>>, "Upload"=>"Submit Query"}
Completed 200 OK in 64ms (Views: 0.4ms | ActiveRecord: 0.9ms)

这是我正在调用的 rails 中的操作

Here is the action in rails that I am calling

def create
     @user = User.find_by_fbid(params[:fbid])

     if @user.nil?
       #create user and register if user does not exist
       @user = User.new( :fbid => params[:fbid] )
       @user.save
     end

    if params[:Filedata]
      @image = @user.images.build()
      @image.swfupload_file = params[:Filedata]

      if @image.save
        render :json => { :data => @image, :success => true }
      else
        render :json => { :info => "error", :success => false }
      end
    else
      @image = Image.new params[:img]
      if @image.save
        render :json => { :data => @bowl, :success => true }
      else
        render :json => { :info => "error", :success => false }
      end
    end
  end
end

基本上一个用户可以有很多图像,所以我必须确保用户存在.如果它们不存在,我首先创建一个新用户.

Basically a User can have many images so I have to make sure the User exists. If they do not exist the I create a new user first.

我还有另一种方法,可以让我获取用户上传的最后一张图片的路径,该图片也在生产中返回错误.

I Also have another method that allows me to grab the path to the last image the user uploads that is also returning an error in production.

  def last_img
    @user = User.find_by_fbid(params[:fbid])

    if @user.nil?
      render :json => { :error => "no bowls for this user" }
    else
      bowl = @user.images.first

      render :json => { :img_path => image.img.url}
    end
  end

我为此得到的错误如下ImagesController#last_image

the error that I am getting for this is the following NoMethodError in ImagesController#last_image

nil:NilClass 的未定义方法 `img'

undefined method `img' for nil:NilClass

推荐答案

我对你的代码感到有点迷茫.

I feel a little bit lost with your code.

如果它确实是您的实时代码的副本,那么 image.img 可能会在 #last_img 中抛出异常,因为它可能未初始化(至少没有初始化)在您提供的代码中).但它会引发不同类型的异常,而不是 nil:NilClass

If it really is a copy of your live code then the image.img probably would throw an exception in #last_img because it is probably not initialized (at least not in code you've provided). But it would raise a different kind of exception not a nil:NilClass

如果它是一个错字并且你修改了 @image.img 那么问题是一样的 - 你的控制器的工作流程是什么 - 如果它被按原样调用,那么它真的会抛出 nil:NilClass 因为在 #last_img

In case that it's a typo and you ment @image.img then the question is same - what is a workflow of your controller - if it's called as it is then it would really throw nil:NilClass because there is not @image initialized anywhere in the code of #last_img

还有一件事 - 您正在那里初始化局部变量 bowl 并且没有使用它?

And another thing - you are initializing local variable bowl there and there is no use of it?

最后一个,现在在 #create - @bowl 是从哪里来的?从提供的代码来看,它应该总是 nil.

And last one, now in #create - where did @bowl came from? From provided code it should be always nil.

这篇关于在生产中为 rails 使用回形针插件时出错.图像未保存到服务器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆