2011-04-21 4 views
7

나는 사용자가 다른 데이터를 변경하는 것과 함께 아바타를 업로드 할 수 있도록 장치 등록 컨트롤러를 무시하려고 시도하고 업로드 후 사용자 그림을 자릅니다. devise registrations 컨트롤러 + paperclip

는 내가 만들어 자르기 뷰를 모든 necesarry 사용자 클립 속성을 추가, 내 등록 컨트롤러는 다음과 같습니다

class RegistrationsController < Devise::RegistrationsController 
    def update 

    if params[resource_name][:avatar].blank? 
      super 
    else 
      @user=resource 
     respond_to do |format| 
     if resource.update_attributes(params[resource_name]) 
      flash[:notice]='Avatar successfully uploaded.' 
      format.html { 
        render :action => 'crop' 
      } 
      format.xml { head :ok } 
      else 
      format.html { render :action => "editpicture" } 
      format.xml { render :xml => @demotivator.errors, :status => :unprocessable_entity } 
      end 
     end 
    end 
    end 

end 

을하지만 난 사진과 함께 양식을 제출할 때, 아무것도 파이어 폭스는 "로딩 표시하는 것을 제외하고 발생하지 않습니다. .. "영원히! 개발 로그에 전혀 업데이트하지 .. :(

사람이 내가 잘못된 일을 할 수 있는지 말해 줄 수

PS 사용자 편집 형태가 같다?.

답변

7

난 그냥에 있었다 발생 사용자 모델에

attr_accessible :avatar 

를 추가하고, 당신이 경우 제대로

+4

그래도 Rails 4 앱에서 어떻게 이루어 집니까? –

2

작업 시작 `

def configure_permitted_parameters 
     devise_parameter_sanitizer.permit(:account_update, keys: [:firstname, 
        :lastname, :username, :password, :email, :bio, 
        :avatar,:password_confirmation, :current_password ]) 
end` 
  • 이 태그를 추가해야합니다 : 레일 4를 사용하여 확인 PARAM은 다음과 같은 컨트롤러에 허용 만드는 RegistrationsController

    # get devise to recognize the custom fields of the user model 
    before_filter :configure_permitted_parameters, if: :devise_controller? 
    
    protected 
    
        def configure_permitted_parameters 
         devise_parameter_sanitizer.for(:account_update) do |u| 
          u.permit(:avatar, :email, :password, :password_confirmation) 
         end 
        end 
    
  • 0
    1. 에 다음을 추가 : :html => { :multipart => true }을 양식에 입력하십시오 :

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

    관련 문제