设计一下,让配准控制器接受图像?
我更新了views/devise/registrations/edit.html.erb以支持用户的回形针照片(User.photo):
<%= form_for(resource, :as => resource_name, :url => registration_path(resource_name), :html => { :method => :put, :multipart => true }) do |f| %>
<p><%= f.label :photo %><br />
<%= f.file_field :photo %></p>
这似乎提交得很好:
Started POST "/users" for 127.0.0.1 at Tue Jun 14 13:00:27 -0700 2011
Processing by Devise::RegistrationsController#update as HTML
Parameters: {"commit"=>"Update", "authenticity_token"=>"2beiFZYBwuUdTprM3QARML6SQlH9yz/oWzPqfdj1GdQ=", "utf8"=>"✓", "user"=>{"photo"=>#<ActionDispatch::Http::UploadedFile:0x103126b60 @tempfile=#<File:/var/folders/lF/lF0Ne5vGFj44kV54W3zBdU+++TI/-Tmp-/RackMultipart20110614-3154-l07lvd-0>, @original_filename="screenshot-3.png", @headers="Content-Disposition: form-data; name=\"user[photo]\"; filename=\"screenshot-3.png\"\r\nContent-Type: image/png\r\n", @content_type="image/png">, "password_confirmation"=>"[FILTERED]", "current_password"=>"[FILTERED]", "password"=>"[FILTERED]", "email"=>"[email protected]"}}
User Load (0.2ms) SELECT "users".* FROM "users" WHERE "users"."id" = 1 LIMIT 1
CACHE (0.0ms) SELECT "users".* FROM "users" WHERE "users"."id" = 1 LIMIT 1
[paperclip] identify -format %wx%h '/var/folders/lF/lF0Ne5vGFj44kV54W3zBdU+++TI/-Tmp-/stream20110614-3154-1ozp24i-0.png[0]' 2>/dev/null
[paperclip] convert '/var/folders/lF/lF0Ne5vGFj44kV54W3zBdU+++TI/-Tmp-/stream20110614-3154-1ozp24i-0.png[0]' -resize "300x300>" '/var/folders/lF/lF0Ne5vGFj44kV54W3zBdU+++TI/-Tmp-/stream20110614-3154-1ozp24i-020110614-3154-zrpy05-0' 2>/dev/null
[paperclip] identify -format %wx%h '/var/folders/lF/lF0Ne5vGFj44kV54W3zBdU+++TI/-Tmp-/stream20110614-3154-1ozp24i-0.png[0]' 2>/dev/null
[paperclip] convert '/var/folders/lF/lF0Ne5vGFj44kV54W3zBdU+++TI/-Tmp-/stream20110614-3154-1ozp24i-0.png[0]' -resize "100x100>" '/var/folders/lF/lF0Ne5vGFj44kV54W3zBdU+++TI/-Tmp-/stream20110614-3154-1ozp24i-020110614-3154-10hkm68-0' 2>/dev/null
Rendered devise/registrations/edit.html.erb within layouts/application (13.3ms)
Completed 200 OK in 385ms (Views: 17.9ms | ActiveRecord: 0.2ms)
但由于某种原因它没有保存到数据库?
有什么想法吗?
I updated views/devise/registrations/edit.html.erb to support a paperclip photo for the user (User.photo):
<%= form_for(resource, :as => resource_name, :url => registration_path(resource_name), :html => { :method => :put, :multipart => true }) do |f| %>
<p><%= f.label :photo %><br />
<%= f.file_field :photo %></p>
This seems to be submitting fine:
Started POST "/users" for 127.0.0.1 at Tue Jun 14 13:00:27 -0700 2011
Processing by Devise::RegistrationsController#update as HTML
Parameters: {"commit"=>"Update", "authenticity_token"=>"2beiFZYBwuUdTprM3QARML6SQlH9yz/oWzPqfdj1GdQ=", "utf8"=>"✓", "user"=>{"photo"=>#<ActionDispatch::Http::UploadedFile:0x103126b60 @tempfile=#<File:/var/folders/lF/lF0Ne5vGFj44kV54W3zBdU+++TI/-Tmp-/RackMultipart20110614-3154-l07lvd-0>, @original_filename="screenshot-3.png", @headers="Content-Disposition: form-data; name=\"user[photo]\"; filename=\"screenshot-3.png\"\r\nContent-Type: image/png\r\n", @content_type="image/png">, "password_confirmation"=>"[FILTERED]", "current_password"=>"[FILTERED]", "password"=>"[FILTERED]", "email"=>"[email protected]"}}
User Load (0.2ms) SELECT "users".* FROM "users" WHERE "users"."id" = 1 LIMIT 1
CACHE (0.0ms) SELECT "users".* FROM "users" WHERE "users"."id" = 1 LIMIT 1
[paperclip] identify -format %wx%h '/var/folders/lF/lF0Ne5vGFj44kV54W3zBdU+++TI/-Tmp-/stream20110614-3154-1ozp24i-0.png[0]' 2>/dev/null
[paperclip] convert '/var/folders/lF/lF0Ne5vGFj44kV54W3zBdU+++TI/-Tmp-/stream20110614-3154-1ozp24i-0.png[0]' -resize "300x300>" '/var/folders/lF/lF0Ne5vGFj44kV54W3zBdU+++TI/-Tmp-/stream20110614-3154-1ozp24i-020110614-3154-zrpy05-0' 2>/dev/null
[paperclip] identify -format %wx%h '/var/folders/lF/lF0Ne5vGFj44kV54W3zBdU+++TI/-Tmp-/stream20110614-3154-1ozp24i-0.png[0]' 2>/dev/null
[paperclip] convert '/var/folders/lF/lF0Ne5vGFj44kV54W3zBdU+++TI/-Tmp-/stream20110614-3154-1ozp24i-0.png[0]' -resize "100x100>" '/var/folders/lF/lF0Ne5vGFj44kV54W3zBdU+++TI/-Tmp-/stream20110614-3154-1ozp24i-020110614-3154-10hkm68-0' 2>/dev/null
Rendered devise/registrations/edit.html.erb within layouts/application (13.3ms)
Completed 200 OK in 385ms (Views: 17.9ms | ActiveRecord: 0.2ms)
But it isn't saving to the DB for some reason?
Any ideas why that would be?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我记得设计限制了可以直接从蝙蝠访问的属性。
如果添加
到用户模型中它可以工作吗?
I remember Devise limiting the attributes that are accessible right from the bat.
If you add
to your user model does it work?
我遇到了同样的问题。我认为你应该确保在你的
ApplicationController
中并定义方法
def configure_permissed_parameters
devise_parameter_sanitizer.for(:sign_up) { |u| u.permit(:照片,...这里) }
结尾
I ran through the same issue. I think you should ensure that in you
ApplicationController
and the define the method
def configure_permitted_parameters
devise_parameter_sanitizer.for(:sign_up) { |u| u.permit(:photo,...here ) }
end