title: Rails: first_or_create not saving
body: <p>My goal for my application is to only show a form page with existing data or a blank form if new. I've accomplished this by using a callback that created a blank record when the user is created.</p>
  
  <p>User model:</p>
  
  <pre><code>before_create :build_health_profile
  </code></pre>
  
  <p>However, if for whatever reason a users "health_profile" were to be destroyed or non-existant, it breaks my entire app with:</p>
  
  <p>"undefined method `health_profile' for nil:NilClass"</p>
  
  <p>It was mentioned to me that the "first_or_create" method could solve this by show a new form or finding the existing one, but I can't get it to save the fields. It directs to my root with my save alert like it saved, but nothing gets actually saved.</p>
  
  <p>Controller:</p>
  
  <pre><code>class HealthProfilesController &lt; ApplicationController
  
    def new
      @health_profile = current_user.build_health_profile
    end
  
    def create
      @health_profile = HealthProfile.where(user_id: current_user).first_or_create(health_profile_params)
      if @health_profile.save
        flash[:success] = "Health profile saved."
        redirect_to root_path
      else
        render 'new'
      end
    end
  
    private
  
    def health_profile_params
      params.require(:health_profile).permit(
         :age,
         :weight,
         :height,
         :gender
      )
    end
  end
  </code></pre>
  
  <p>I've seen where I could use a block for "first_or_create", but no luck getting that to work.</p>
  
  <p>View:</p>
  
  <pre><code>&lt;%= link_to "Health Profile", new_health_profile_path %&gt;
  </code></pre>
  
  <p>Models:</p>
  
  <pre><code>class User &lt; ActiveRecord::Base
    has_one :health_profile, dependent: :destroy
  end
  
  class HealthProfile &lt; ActiveRecord::Base
     belongs_to :user
  end
  </code></pre>