I am trying to create a new page called edit_profile for my User model so that the user can edit his profile (line). I follow http://railscasts.com/episodes/41-conditional-validations
Here is the form (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 %>
The problem I am facing is that I have a password check and password confirmation. When I load the edit_profile view, I continue to receive this message Password is too short (minimum is 6 characters)even before I try to submit a new profile.
Here is my 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
How to get around password verification when I just want to change the profile attribute in a user model?
Thank!
Other relevant information:
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,
:length => { :within => 6..40 }
validates :profile, :length => { :maximum => 160 }
end