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 %>
您是否嘗試過重新啓動自安裝ImageMagick的服務器? – PhillipKregg 2012-02-26 19:14:46