2013-02-24 3 views
1

다음 코드를 사용하여 루트 레일 디렉토리의/public/uploads/폴더에 이미지를 업로드하고 있습니다.이미지 업로드를 시도 할 때 인코딩 :: UndefinedConversionError

uploaded_io = params[:product_image] 
File.open(Rails.root.join('public','uploads', uploaded_io.original_filename), 'w') do |file| 
    file.write(uploaded_io.read) 
end 

내 양식이

<%= form_tag({:action => :configure_product}, :multipart => true) do %> 
<%= label_tag(:product_image, "Image:") %><br /> 
<%= file_field_tag 'product_image' %> 
<%= submit_tag "Save and add another", :name => 'save and add another' %> 
<%= submit_tag "Save", :name => 'save' %> 
<% end %> 

처럼 보이지만, 나는 다음과 같은 오류가 양식을 제출하려고 할 때.

인코딩 :: UndefinedConversionError #의 configure_product ConfigureCategoryController에서

지금 'WB'와에 내가 무엇입니까 'W'UTF-8

내가에서 쓰기 모드를 대체

"\ XFF"ASCII-8BIT에서에 ConfigureCategoryController 번호의 configure_product에서

NoMethodError

정의되지 않은 메서드`이름 '무기 호에 대한 : NilClass

레일에서 새로운 소식입니다. 반드시 도움을 주셔서 감사합니다.

+0

그럼 어떻게 고쳤습니까? –

답변

5

열기 유형에 b를 추가하여 파일을 이진 파일로 열어야합니다.

File.open("#{ Rails.root }/tmp/uploaded_image.gif", "wb") do |f| 

다른 문제는 응용 프로그램과 관련이 있습니다.

관련 문제