Note that there are some explanatory texts on larger screens.

plurals
  1. PORails - Validation across two forms
    primarykey
    data
    text
    <p>I have what seems to be a non-standard signup process:</p> <p>[welcome! enter your email and password] => [cool, enter a lot more information] => [registered]</p> <p>I'm having trouble getting rails to recognize that I want to validate only the email and password on page 1, and all the other stuff on page 2. </p> <p>When the user hits the site, they see my welcome page:</p> <pre><code>class WelcomeController &lt; ApplicationController def index @user = User.new end end &lt;%= form_for(@user) do %&gt; &lt;div class="formItem"&gt; &lt;%= label_tag(:email, "Your email address:") %&gt; &lt;%= text_field(:user, :email) %&gt; &lt;br clear="all" /&gt; &lt;/div&gt; &lt;div class="formItem"&gt; &lt;%= label_tag(:password, "Select a password:") %&gt; &lt;%= password_field_tag(:password) %&gt; &lt;br clear="all" /&gt; &lt;/div&gt; &lt;%= submit_tag("Sign up today - it's free and easy!", :class =&gt; "submitForm") %&gt; &lt;% end %&gt; </code></pre> <p>=</p> <pre><code>class UsersController &lt; ApplicationController def create @user = User.new(params[:user]) if @user.save redirect_to(edit_user_path(@user, :noticeHeader =&gt; true ), :notice =&gt; 'Please take a minute and answer these additional questions.') else render :action =&gt; "welcome/index" end end </code></pre> <p>=</p> <p>Once they click Sign Up, they see my next page of form fields.</p> <p>The problem I'm running into is that I validates_presence_of fields that are on both pages, in the user model. Since these fields aren't on the welcome page, I get a "<strong>undefined local variable or method</strong>" error upon submitting the welcome page. For example, I <strong>validates_presence_of :title</strong> because I want title to be required, but it's only listed on page 2, so page 1 doesn't validate properly. </p> <p>Thoughts on how to handle this?</p> <p>Thanks.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    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.
    1. This table or related slice is empty.
    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