Note that there are some explanatory texts on larger screens.

plurals
  1. POUpdating user profile without having to enter the password and confirmation each time
    primarykey
    data
    text
    <p>I'm trying to create a new page called edit_profile for my User model so that the user can edit his profile(string). I'm following <a href="http://railscasts.com/episodes/41-conditional-validations" rel="nofollow">http://railscasts.com/episodes/41-conditional-validations</a></p> <p>Here is the form (edit_profile.html.erb):</p> <pre><code> &lt;%= form_for @user, :html =&gt; { :multipart =&gt; true } do |f| %&gt; &lt;div class="field"&gt; &lt;%= f.label :profile %&gt;&lt;br/&gt; &lt;%= f.text_area :profile, :class =&gt; "round" %&gt;&lt;br /&gt; &lt;/div&gt; &lt;div class="actions"&gt; &lt;%= submit_tag "update", :id =&gt; "updateSubmit" %&gt; &lt;/div&gt; &lt;% end %&gt; </code></pre> <p>The problem I'm having is that I have validation for the presence of password and password confirmation. When I load my edit_profile view, I keep getting this message <code>Password is too short (minimum is 6 characters)</code> even before I try to submit a new profile.</p> <p>Here is my users_controller.rb:</p> <pre><code>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 </code></pre> <p><strong>How do I bypass my password validation when I just want to edit my profile attribute in the user model?</strong></p> <p>Thanks!</p> <p>Other relevant information:</p> <p>user.rb</p> <pre><code>class User &lt; 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 =&gt; :should_validate_password? validates_confirmation_of :password, :if =&gt; :should_validate_password? def should_validate_password? updating_password || new_record? end validates :name, :presence =&gt; true, :name_format =&gt; true, :uniqueness =&gt; { :case_sensitive =&gt; false } validates :email, :presence =&gt; true, :email_format =&gt; true, :uniqueness =&gt; { :case_sensitive =&gt; false } validates :password, #:presence =&gt; true, #:confirmation =&gt; true, :length =&gt; { :within =&gt; 6..40 } validates :profile, :length =&gt; { :maximum =&gt; 160 } end </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload