下午全部,
我正在尝试使用carrierwave在注册时上传图片。谁能告诉我为什么params会回滚或指向正确的方向。我正在使用设计的标准注册控制器,并没有创建我自己的。
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"=>"shaun@shaun.com",
"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" = 'shaun@shaun.com' LIMIT 1
(0.3ms) ROLLBACK
好的,我一直试图弄明白这一整夜。我现在已经创建了一个自定义控制器并在其中插入了pry。这是如下所示的过程:
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
所以,当我到达这个断点并检查params时,这就是显示的内容,就在它跳转到其他地方之前:
[2] pry(#<RegistrationsController>)> sign_up_params
=> {"first_name"=>"Marlene",
"last_name"=>"Annoying",
"profile_name"=>"AnnoyingMarlene",
"email"=>"mannoying@smelly.com",
"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 :(得分:1)
错误消息不言自明:User Exists
。可能您已经在数据库中拥有"email" = 'shaun@shaun.com'
的用户,并且此电子邮件必须是唯一的。
答案 1 :(得分:0)
如果没有其他用户,请尝试使用User.delete_all,然后重试。 您还在使用哪个数据库?
答案 2 :(得分:0)
如果您使用的是.save,只需输入@ object.errors然后在控制台中检查错误消息是什么
如果你正在使用.save!将其更改为.save然后看上面
答案 3 :(得分:0)
我发现了问题。当通过source安装imagemagick时,Carrierwave不喜欢它。如果您使用的是ubuntu,请确保使用
进行安装sudo apt-get install imagemagick
然后mini-magick似乎正确地与imagemagick对话,我现在有了个人资料图片。