开发者

Devise, Getting the registration controller to accept an image?

开发者 https://www.devze.com 2023-03-13 11:39 出处:网络
I updated views/devise/registrations/edit.html.erb to support a paperclip photo for the user (User.photo):

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"=>"name@gmail.com"}}
  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?


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?


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

0

精彩评论

暂无评论...
验证码 换一张
取 消