2012-02-26 94 views
2

前:使用CarrierWave,我没有问题以崭新的形象更新的用户配置文件中的图像。Rails的:无法转换成零字符串错误信息

然后:我安装的ImageMagick

后:当我尝试在用户配置文件更新的形象,我得到一个“不能转换零到字符串”错误消息。但是,如果我不选择一个新的形象,只要按“更新”它工作正常(即它显示的原始图像)

任何人都可以看到的问题可能是什么?

TypeError in UsersController#update 

can't convert nil into String 
Rails.root: /Users/mm/Sites/AT 

Application Trace | Framework Trace | Full Trace 
app/controllers/users_controller.rb:64:in `block in update' 
app/controllers/users_controller.rb:63:in `update' 

参数

{"utf8"=>"✓", 
"_method"=>"put", 
"authenticity_token"=>"N1/rSIzBwYLFecQ59tCasRpt6Tst7GOSvdEob93ZrrA=", 
"user"=>{"name"=>"M", 
"email"=>"[email protected]", 
"image"=>#<ActionDispatch::Http::UploadedFile:0x00000102fef328 @original_filename="btc.jpg", 
@content_type="image/jpeg", 
@headers="Content-Disposition: form-data; name=\"user[image]\"; filename=\"btc.jpg\"\r\nContent-Type: image/jpeg\r\n", 
@tempfile=#<File:/var/folders/rc/rcFucU9oF5qT5vZE+tL1JE+++TI/-Tmp-/RackMultipart20120226-20685-1x4k7ph>>}, 
"commit"=>"Update User", 
"id"=>"2"} 

UsersController

def update 
    @user = User.find(params[:id]) 

    respond_to do |format| 
     if @user.update_attributes(params[:user]) 
     format.html { redirect_to @user, notice: 'User was successfully updated.' } 
     format.json { head :ok } 
     else 
     format.html { render action: "edit" } 
     format.json { render json: @user.errors, status: :unprocessable_entity } 
     end 
    end 
    end 

形式

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

     <ul> 
     <% @user.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 :email %><br /> 
    <%= f.text_field :email %> 
    </div> 
    <div class="field"> 
    <%= f.file_field :image %><br /> 

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

您是否尝试过重新启动自安装ImageMagick的服务器? – PhillipKregg 2012-02-26 19:14:46

回答

0

问题是,我并没有开始与亚马逊关键服务器,以便文件WASN上传,所以我当试图显示图像时,t不能将nil转换为字符串。

相关问题