title: Split Form User Update Rails
body: <p>Recently, I decided to split my User Form into an Edit &amp; Account Form.</p>
  
  <p>User Edit Form </p>
  
  <pre><code>-Name
  -Username
  -AboutMe
  </code></pre>
  
  <p>User Account Form</p>
  
  <pre><code>-Email
  -Password
  -Password Confirmation
  </code></pre>
  
  <p>The routes work fine and everything gets updated accordingly. But for some reason, when my User Model validates the Email Presence &amp; it Fails, it renders the Edit Form with the appropriate Error Messages as oppose to the Account Form. </p>
  
  <p><strong>How can I set up my Update Method in my Controller to know which form to Render with the appropriate error messages?</strong></p>
  
  <p>Model</p>
  
  <pre><code>class User &lt; ActiveRecord::Base
    attr_accessible :name, :email, :password, :password_confirmation, :username
  
    validates :username, :presence   =&gt; true,
                       :length     =&gt; { :maximum =&gt; 15 },
                       :format     =&gt; { :with =&gt; VALID_UNAME_REGEX },
                       :uniqueness =&gt; { :case_sensitive =&gt; false }
  
    validates :email, presence:   true,
                  format:     { with: VALID_EMAIL_REGEX },
                  uniqueness: { case_sensitive: false }
  
    validates :password, presence: true, length: { minimum: 6 }, :if =&gt; :password #only validate if password changed!
    validates :password_confirmation, presence: true, :if =&gt; :password
  
  end
  </code></pre>
  
  <p>Views</p>
  
  <pre><code>Edit View
  
  &lt;%= form_for @user, :html =&gt; { :multipart =&gt; true } do |f| %&gt;
    &lt;%= render 'shared/error_messages', object: f.object %&gt;
  
    &lt;div class="statictitle"&gt;Your Profile&lt;/div&gt;
  
      &lt;%= f.text_field :username, placeholder: "Username..", :class =&gt; "form-control" %&gt;
  
      &lt;%= f.text_field :name, placeholder: "Name", :class =&gt; "form-control" %&gt;
  
      &lt;%= f.text_area :bio, placeholder: "About yourself in 160 characters or less...", class: "textinput" %&gt;
  
    &lt;%= f.submit "Update Profile", class: "btn btn-primary" %&gt;&lt;br&gt;
  
  &lt;% end %&gt;
  
  Account View
  
  &lt;%= form_for @user, :html =&gt; { :multipart =&gt; true } do |f| %&gt;
    &lt;%= render 'shared/error_messages', object: f.object %&gt;
  
    &lt;div class="statictitle"&gt;Your Account&lt;/div&gt;
  
      &lt;%= f.text_field :email, placeholder: "Email", :class =&gt; "form-control" %&gt;
  
      &lt;%= f.password_field :password, placeholder: "Password", :class =&gt; "form-control" %&gt;
  
      &lt;%= f.password_field :password_confirmation, placeholder: "Password Confirmation", :class =&gt; "form-control" %&gt;
  
    &lt;%= f.submit "Update Account", class: "btn btn-primary" %&gt;&lt;br&gt;
  
  &lt;% end %&gt;
  </code></pre>
  
  <p>Controller</p>
  
  <pre><code>class UsersController &lt; ApplicationController
  
    def edit
      @user = User.find_by_username(params[:id])
    end
  
    def account
      @title = "Account"
      @user = User.find_by_username(params[:id])
    end
  
    def update
      @user = User.find(current_user.id)
      if @user.update_attributes(params[:user])
        flash[:success] = "Profile updated"
        sign_in @user
        redirect_to user_url
      else
        render 'edit'      ###I can't seem to figure out how to render the correct form
      end
    end
  
  end
  </code></pre>
  
  <p>Routes</p>
  
  <pre><code>resources :users do
    member do
      get :account
    end  
  end
  </code></pre>