2013-11-20 32 views
0

下午所有,在註冊時設計回滾

我正在嘗試使用載波上傳圖片進行註冊。誰能告訴我爲什麼這些參數回滾或指向正確的方向。我正在使用設計的標準註冊控制器,並沒有創建自己的。

Started POST "/users" for 127.0.0.1 at 2013-11-20 15:16:15 +0100 
    Processing by Devise::RegistrationsController#create as HTML 
     Parameters: {"utf8"=>"✓", "authenticity_token"=>"bB/oSY5s5ohDqivn63sbbehPxQxzkVlt5WVB7BDYNsI=", 
"user"=>{"first_name"=>"Shaun", "last_name"=>"Shaun", 
"profile_name"=>"Shaunj9k", "email"=>"[email protected]", 
"password"=>"[FILTERED]", "password_confirmation"=>"[FILTERED]", 
"avatar"=>#<ActionDispatch::Http::UploadedFile:0x007f3d94a114d0 
@tempfile=#<File:/tmp/RackMultipart20131120-18938-onc1k9>, @original_filename="12673_607433832654038_1101803441_n.jpg", 
@content_type="image/jpeg", @headers="Content-Disposition: form-data; name=\"user[avatar]\"; filename=\"12673_607433832654038_1101803441_n.jpg\"\r\nContent-Type: image/jpeg\r\n">, 
"avatar_cache"=>""}, 
"commit"=>"Sign up"} 
     (0.7ms) BEGIN 
     User Exists (71.8ms) SELECT 1 AS one FROM "users" WHERE "users"."email" = '[email protected]' LIMIT 1 
     (0.3ms) ROLLBACK 

好吧,我一直想弄明白這一點。我現在已經創建了一個自定義控制器,並將其撬在裏面。這是如下過程:

def create 
    build_resource(sign_up_params) 
binding.pry 
    if resource.save 
     yield resource if block_given? 
     if resource.active_for_authentication? 
     set_flash_message :notice, :signed_up if is_flashing_format? 
     sign_up(resource_name, resource) 
     respond_with resource, :location => after_sign_up_path_for(resource) 
     else 
     set_flash_message :notice, :"signed_up_but_#{resource.inactive_message}" if is_flashing_format? 
     expire_data_after_sign_in! 
     respond_with resource, :location => after_inactive_sign_up_path_for(resource) 
     end 
    else 
     clean_up_passwords resource 
     respond_with resource 
    end 

    end 

所以,當我得到這個斷點和檢查參數,可以這是所示,它跳躍的權利之前,其他:

[2] pry(#<RegistrationsController>)> sign_up_params 
=> {"first_name"=>"Marlene", 
"last_name"=>"Annoying", 
"profile_name"=>"AnnoyingMarlene", 
"email"=>"[email protected]", 
"password"=>"admin1234", 
"password_confirmation"=>"admin1234", 
"avatar"=> 
    #<ActionDispatch::Http::UploadedFile:0xb2f69d18 
    @content_type="image/jpeg", 
    @headers= 
    "Content-Disposition: form-data; name=\"user[avatar]\"; filename=\"picture.jpeg\"\r\nContent-Type: image/jpeg\r\n", 
    @original_filename="picture.jpeg", 
    @tempfile=#<File:/tmp/RackMultipart20131121-14703-1fubdpu>>, 
"avatar_cache"=>"1385025876-14703-8014/Link_to_sublime_text"} 

這裏是商店目錄在AvatarUploader.rb

def store_dir 
    "uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}" 
    end 
+0

你能在'create'行爲的'@ user.errors.full_messages'數組中找到什麼? – marzapower

+0

我正在使用設計的註冊控制器,所以我會如何顯示。 –

+0

Uhm,一個快速的方法:嘗試使用'User.create!({...})'在'pry'中使用相同的參數。然後尋找錯誤 – marzapower

回答

0

我發現了這個問題。當通過源代碼安裝imagemagick時,Carrierwave不喜歡它。如果您在使用Ubuntu確保安裝使用

sudo apt-get install imagemagick 

然後迷你magick似乎正常交談,ImageMagick的,瞧我現在有資料圖片。

1

該錯誤消息是不言自明:User Exists。可能您已經擁有數據庫中的用戶"email" = '[email protected]',並且此電子郵件必須是唯一的。

+0

該用戶不存在,我之前檢查了數據庫... –

+0

您是否嘗試'rake db:reset'數據庫? – marzapower

+0

更新的問題,空數據庫仍然說用戶存在? –

0

如果沒有其他用戶並嘗試重試,請嘗試User.delete_all。 你還使用哪個數據庫?

0

如果你正在使用.save,只是把@ object.errors然後在控制檯中有什麼錯誤信息

如果您正在使用.save檢查!將其更改爲.save然後看到上面