2014-10-19 4 views
0

양식에 업로드 할 사진 옵션을 만들려고합니다. 나는 그렇게하기 위해 carrierwave를 사용하고있다. 문제없이 양식을 실행할 수 있지만 변경 사항을 업로드하고 저장할 때 postgres 데이터베이스 열을 확인하고 avatar 열이 여전히 비어 있음을 확인합니다. 이미지가 저장되지 않았습니다. 여기 반송파 이미지를 postgresql 테이블에 업로드

<h2>Edit <%= resource_name.to_s.humanize %></h2> 

<%= form_for(resource, as: resource_name, url: registration_path(resource_name), html: { method: :put , :multipart => true}) do |f| %> 
    <%= devise_error_messages! %> 

    <div><%= f.label :email %><br /> 
    <%= f.email_field :email, autofocus: true %></div> 

    <% if devise_mapping.confirmable? && resource.pending_reconfirmation? %> 
    <div>Currently waiting confirmation for: <%= resource.unconfirmed_email %></div> 
    <% end %> 

    <div><%= f.label :password %> <i>(leave blank if you don't want to change it)</i><br /> 
    <%= f.password_field :password, autocomplete: "off" %></div> 

    <div><%= f.label :password_confirmation %><br /> 
    <%= f.password_field :password_confirmation, autocomplete: "off" %></div> 

    <div><%= f.label :current_password %> <i>(we need your current password to confirm your changes)</i><br /> 
    <%= f.password_field :current_password, autocomplete: "off" %></div> 

    <!-- add profile picture portion --> 

    <div><%= f.label :avatar %><br /> 
    <%= f.file_field :avatar %> 


    <div><%= f.submit "Update" %></div> 
<% end %> 

내 모델 :

class User < ActiveRecord::Base 
    # Include default devise modules. Others available are: 
    # :confirmable, :lockable, :timeoutable and :omniauthable 
    devise :database_authenticatable, :registerable, 
     :recoverable, :rememberable, :trackable, :validatable 

    mount_uploader :avatar, AvatarUploader 
end 

그리고 여기 내 업 로더입니다 : 질문 코멘트 스레드의

class AvatarUploader < CarrierWave::Uploader::Base 
    def store_dir 
    "uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}" 
    end 

    def extension_white_list 
    %w(jpg jpeg gif png) 
    end 
end 
+0

pas 모델의 코드 및 이동 통신사 웨이브 업 로더 클래스를 테스트합니다. –

+0

은 컨트롤러의 '허용 된 매개 변수'에 포함 된 아바타 필드입니까? –

+0

@ joshua.paling 필자는 지금까지 단 하나의 컨트롤러 만 가지고 있으며 ApplicationController는 – Liondancer

답변

관련 문제