私のユーザーモデルにedit_profileという新しいページを作成して、ユーザーがプロフィール(文字列)を編集できるようにしようとしています。私はここでパスワードを入力せずにユーザープロファイルを更新し、毎回確認します。
http://railscasts.com/episodes/41-conditional-validationsを次の形式(edit_profile.html.erb)ですよ:
<%= form_for @user, :html => { :multipart => true } do |f| %>
<div class="field">
<%= f.label :profile %><br/>
<%= f.text_area :profile, :class => "round" %><br />
</div>
<div class="actions">
<%= submit_tag "update", :id => "updateSubmit" %>
</div>
<% end %>
私がいる問題は、私は、パスワードとパスワードの確認の有無の検証を持っているということです。 edit_profileビューを読み込むと、新しいプロファイルを送信しようとしても、このメッセージが表示され続けます。Password is too short (minimum is 6 characters)
ここで
は私users_controller.rbです:
def edit_profile
@user = current_user
@user.updating_password = false
@user.save
@title = "Edit profile"
end
def update
@user = User.find(params[:id])
if @user.update_attributes(params[:user])
flash[:success] = "Account updated."
redirect_to @user
else
@title = "Edit user"
render 'edit'
end
end
私は、ユーザーモデルで私のプロファイル属性を編集したいとき、私は自分のパスワード検証をバイパスするにはどうすればよいですか?
ありがとうございました!
その他の関連情報:
user.rb
class User < ActiveRecord::Base
attr_accessor :password, :updating_password
attr_accessible :name, :email, :password, :password_confirmation, :photo,
:profile
before_save :downcase_fields
before_save :encrypt_password
validates_presence_of :password, :if => :should_validate_password?
validates_confirmation_of :password, :if => :should_validate_password?
def should_validate_password?
updating_password || new_record?
end
validates :name, :presence => true,
:name_format => true,
:uniqueness => { :case_sensitive => false }
validates :email, :presence => true,
:email_format => true,
:uniqueness => { :case_sensitive => false }
validates :password,
#:presence => true,
#:confirmation => true,
:length => { :within => 6..40 }
validates :profile, :length => { :maximum => 160 }
end
Userクラスの外観はどうですか? –
@juwiley自分の投稿に関連情報を含むユーザーモデルを追加しました。 – Huy