设计一下,让配准控制器接受图像?

发布于 2024-11-15 13:49:40 字数 2431 浏览 1 评论 0原文

我更新了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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

北恋 2024-11-22 13:49:40

我记得设计限制了可以直接从蝙蝠访问的属性。

如果添加

attr_accessible :photo

到用户模型中它可以工作吗?

I remember Devise limiting the attributes that are accessible right from the bat.

If you add

attr_accessible :photo

to your user model does it work?

此刻的回忆 2024-11-22 13:49:40

我遇到了同样的问题。我认为你应该确保在你的 ApplicationController

  before_filter :configure_permitted_parameters, if:  :devise_controller?

并定义方法

def configure_permissed_pa​​rameters
devise_parameter_sanitizer.for(:sign_up) { |u| u.permit(:照片,...这里) }
结尾

I ran through the same issue. I think you should ensure that in you ApplicationController

  before_filter :configure_permitted_parameters, if:  :devise_controller?

and the define the method

def configure_permitted_parameters
devise_parameter_sanitizer.for(:sign_up) { |u| u.permit(:photo,...here ) }
end

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文