사용자 설정 페이지에 두 개의 양식이 있습니다. 하나는 모든 기본 설정 용이고 다른 하나는 프로필 사진 용입니다. 사용자의 사진을 업데이트하려고 할 때마다 암호 필드가 다른 양식인데도 "암호는 비워 둘 수 없습니다"라는 오류 메시지가 나타납니다. 양식에 대한사용자 편집 프로필 양식이 작동하지 않습니다.
코드는 :
<%= form_for @user, :html=> { :multipart => true} do |f| %>
<%= render 'shared/error_messages', :object => f.object %>
<div class="field">
<%= f.label :name %><br />
<%= f.text_field :name %>
</div>
<div class="field">
<%= f.label :email %><br />
<%= f.text_field :email %>
</div>
<div class="field">
<%= f.label :password %><br />
<%= f.password_field :password %>
</div>
<div class="field">
<%= f.label :password_confirmation, "Confirmation" %><br />
<%= f.password_field :password_confirmation %>
</div>
<div class="actions">
<%= f.submit "Update" %>
</div>
<% end %>
<%= form_for @user, :html=> { :multipart => true} do |f| %>
<%= f.file_field :photo %>
<br />
<%= f.submit "Update" %>
<% end %>
내 user.rb 파일 :
class User < ActiveRecord::Base
attr_accessor :password
attr_accessible :name, :email, :password, :password_confirmation, :photo
has_attached_file :photo,
:styles => {
:thumb=> "50x50#",
:small => "220x220>" },
:storage => :s3,
:s3_credentials => "#{Rails.root}/config/s3.yml",
:path => "/:style/:id/:filename"
has_many :microposts, :dependent => :destroy
has_many :relationships, :foreign_key => "follower_id",
:dependent => :destroy
has_many :following, :through => :relationships, :source => :followed
has_many :reverse_relationships, :foreign_key => "followed_id",
:class_name => "Relationship",
:dependent => :destroy
has_many :followers, :through => :reverse_relationships, :source => :follower
email_regex = /\A[\w+\-.][email protected][a-z\d\-.]+\.[a-z]+\z/i
validates :name, :presence => true,
:length => { :maximum => 50 }
validates :email, :presence => true,
:format => { :with => email_regex },
:uniqueness => { :case_sensitive => false }
validates :password, :presence => true,
:confirmation => true,
:length => { :within => 6..40 }
before_save :encrypt_password
은 어떤 도움이 크게 감사합니다!
! 감사! – BTHarris