title: Ruby Problems Displaying Variables From New View, but Not Edit
body: <p>In my app I have a quiz in a partial because I need the same (lengthy) quiz for my <code>new</code> and for my <code>edit</code> view.  In the header of the <code>application.html.erb</code> and on my <code>users#show</code> page I display the results from this quiz, once it is taken, using an if/else statement.  For some reason, after a user takes the quiz in the <code>new</code> view it is registering that the quiz has been completed (you can tell by the if/else statement) but not displaying the variables.  However, using the <code>edit</code> view (that calls the same partial <code>_quiz.html.erb</code>) the variables display perfectly.</p>
  
  <p>My <code>new</code> view calls the partial like this:</p>
  
  <pre><code>&lt;%= render partial: "quiz", locals: { url: swing_books_path, method: :post } %&gt;
  </code></pre>
  
  <p>While my <code>edit</code> view calls it like this:</p>
  
  <pre><code>&lt;%= render partial: "quiz", locals: { url: edit_swing_book_path(@swing_book), method: :put } %&gt;
  </code></pre>
  
  <p>The partial looks like this:</p>
  
  <pre><code>&lt;%= form_for @swing_book do |f| %&gt;
    &lt;div class="clearfix"&gt;
      &lt;h1 class="text-center"&gt;
      &lt;%= f.text_field :swing01, class: 'form-control input-1' %&gt;
      &lt;%= f.text_field :swing02, class: 'form-control input-1' %&gt;
      &lt;%= f.text_field :swing03, class: 'form-control input-1' %&gt;
      -
      &lt;%= f.text_field :swing04, class: 'form-control input-1' %&gt;
      &lt;%= f.text_field :swing05, class: 'form-control input-1' %&gt;
      &lt;%= f.text_field :swing06, class: 'form-control input-1' %&gt;
      -
      &lt;%= f.text_field :swing07, class: 'form-control input-1' %&gt;
      &lt;%= f.text_field :swing08, class: 'form-control input-1' %&gt;
      &lt;%= f.text_field :swing09, class: 'form-control input-1' %&gt;
      &lt;%= f.text_field :swing10, class: 'form-control input-1' %&gt;
     &lt;/h1&gt;
  
     &lt;div class="form-group text-center"&gt;
        &lt;%= f.submit "Submit Swing Code", class: 'btn btn-success' %&gt;
     &lt;/div&gt;
   &lt;/div&gt;
  &lt;% end %&gt;
  </code></pre>
  
  <p>However, I use these exact same details (with just the variable names changed) on another quiz that is not having the same issue.  (I have three other similar quizzes all of which display perfectly from both <code>new</code> and <code>edit</code> views.)</p>
  
  <p>My model looks like this:</p>
  
  <pre><code>class SwingBook &lt; ActiveRecord::Base
    before_save :set_swing_code
  
    def set_swing_code
      self.swing_code = "#{self.swing01}#{self.swing02}#{self.swing03}-#{self.swing04}#{self.swing05}#{self.swing06}-#{self.swing07}#{self.swing08}#{self.swing09}#{self.swing10}"
    end
  
    belongs_to :user
    validates :user, presence: true
  end
  </code></pre>
  
  <p>My controller looks like this:</p>
  
  <pre><code>class SwingBooksController &lt; ApplicationController
  before_action :require_sign_in
  
  def show
    @swing_book = SwingBook.find(params[:id])
  end
  
  def new
    @swing_book = current_user.build_swing_book
  end
  
  def create
    @swing_book = SwingBook.new
  
    @swing_book.swing_code = params[:swing_book][:swing01]
    @swing_book.swing_code = params[:swing_book][:swing02]
    @swing_book.swing_code = params[:swing_book][:swing03]
    @swing_book.swing_code = params[:swing_book][:swing04]
    @swing_book.swing_code = params[:swing_book][:swing05]
    @swing_book.swing_code = params[:swing_book][:swing06]
    @swing_book.swing_code = params[:swing_book][:swing07]
    @swing_book.swing_code = params[:swing_book][:swing08]
    @swing_book.swing_code = params[:swing_book][:swing09]
    @swing_book.swing_code = params[:swing_book][:swing10]
    @swing_book.swing_code = params[:swing_book][:swing_code]
  
    @swing_book.user = current_user
  
    if @swing_book.save
      flash[:notice] = "Your swing code was saved successfully."
      redirect_to user_path(current_user)
    else
      flash[:alert] = "Sorry, your results failed to save."
      redirect_to welcome_index_path
    end
  end
  
  def edit
    @swing_book = SwingBook.find(params[:id])
  end
  
  def update
    @swing_book = SwingBook.find(params[:id])
  
    @swing_book.assign_attributes(swing_book_params)
  
    if @swing_book.save
      flash[:notice] = "Results were updated successfully."
      redirect_to user_path(current_user)
    else
      flash.now[:alert] = "There was an error saving your results. Please try again."
      redirect_to welcome_index_path
    end
  end
  
  private
  def swing_book_params
    params.require(:swing_book).permit(:swing01, :swing02, :swing03, :swing04, :swing05, :swing06, :swing07, :swing08, :swing09, :swing10, :swing_code)
  end
  end
  </code></pre>
  
  <p>Finally, here's the logic I'm using to display these variables in the <code>application.html.erb</code> file:</p>
  
  <pre><code>&lt;% if current_user.swing_book != nil %&gt;
    &lt;p&gt;ID Code:
      &lt;%= current_user.swing_book.swing01 %&gt;
      &lt;%= current_user.swing_book.swing02 %&gt;
      &lt;%= current_user.swing_book.swing03 %&gt;
      -
      &lt;%= current_user.swing_book.swing04 %&gt;
      &lt;%= current_user.swing_book.swing05 %&gt;
      &lt;%= current_user.swing_book.swing06 %&gt;
      -
      &lt;%= current_user.swing_book.swing07 %&gt;
      &lt;%= current_user.swing_book.swing08 %&gt;
      &lt;%= current_user.swing_book.swing09 %&gt;
      &lt;%= current_user.swing_book.swing10 %&gt;&lt;/p&gt;
  &lt;% end %&gt;
  </code></pre>
  
  <p>And on the <code>user#show</code> page:</p>
  
  <pre><code>&lt;% if @user.swing_book == nil %&gt;
    &lt;h3&gt;ID Code: ???-???-????&lt;%= %&gt;&lt;/h3&gt;
    &lt;p&gt;&lt;%= link_to "Get Your ID Code Now!", new_swing_book_path %&gt;&lt;/p&gt;
  &lt;% else %&gt;
    &lt;h3&gt;ID Code:
      &lt;%= @user.swing_book.swing01 %&gt;
      &lt;%= @user.swing_book.swing02 %&gt;
      &lt;%= @user.swing_book.swing03 %&gt;
      -
      &lt;%= @user.swing_book.swing04 %&gt;
      &lt;%= @user.swing_book.swing05 %&gt;
      &lt;%= @user.swing_book.swing06 %&gt;
      -
      &lt;%= @user.swing_book.swing07 %&gt;
      &lt;%= @user.swing_book.swing08 %&gt;
      &lt;%= @user.swing_book.swing09 %&gt;
      &lt;%= @user.swing_book.swing10 %&gt;&lt;/h3&gt;
    &lt;p&gt;&lt;%= link_to "Update Your Code", edit_swing_book_path(@user.swing_book) %&gt;&lt;/p&gt;
   &lt;% end %&gt;
  </code></pre>
  
  <p>I originally tried displaying just the <code>swing_code</code> variable (as established in the <code>method</code>, but it was displaying a single integer so I switched to the code seen above.  Ideally, I would like to display it as just the <code>swing_code</code> variable, but the (somewhat repetitive) workaround I'm currently using works fine-ish if I could only get the <code>new</code>/<code>edit</code> display issue worked out.</p>
  
  <p>Any ideas as to what could be going wrong?  I can't find any differences between this and the other quizzes that could be causing a problem!</p>