title: rails has_one relationship causing problems - also white screen
body: <p>I have two models: Schedule and Project.  Schedule belongs_To Project and Project has_one schedule.  There are several problems, but i think they all have the same cause.  Here is the code for the schedules#create controller:</p>
  
  <pre><code>def create
              @schedule = Schedule.new(schedule_params)
              @schedule.project  = Project.find(params[:project_id])
              if @schedule.project.student_id == current_user.id
                  if @schedule.save &amp;&amp; @schedule.freelancer_accepts    
                          flash[:notice] = "Successfully created schedule."
                          redirect_to profile_path(current_user.profile_name)  
                  else
                      render :action =&gt; 'new', :notice =&gt; 'Invalid Schedule'
                  end
              else
                  render :action =&gt; 'new', :notice =&gt; 'Schedule is invalid.'
              end
  end
  </code></pre>
  
  <p>Here are the problems:</p>
  
  <ol>
  <li><p>Even though it is a has_one relationship, I am still able to create many schedules for a single project.  This led me to change my controller to this:</p>
  
  <pre><code>def create
      if !Schedule.where(project_id: params[:project_id]).any?
          @schedule = Schedule.new(schedule_params)
          @schedule.project  = Project.find(params[:project_id])
          if @schedule.project.student_id == current_user.id
              if @schedule.save &amp;&amp; @schedule.freelancer_accepts     
                      flash[:notice] = "Successfully created schedule."
                      redirect_to profile_path(current_user.profile_name) 
              else
                  render :action =&gt; 'new', :notice =&gt; 'Invalid Schedule'
              end
          else
              render :action =&gt; 'new', :notice =&gt; 'Schedule is invalid.'
          end
      else
          render :action =&gt; 'new', :notice =&gt; 'A schedule has already been created.'
      end
  end
  </code></pre></li>
  </ol>
  
  <p>The change was that I essentially wrapped the controller in an if that says "if a schedule exists, don't create one.  After I changed my code, I got the following problems:</p>
  
  <ol>
  <li><p>In firefox, when I press the submit button to create a new schedule, i get this error:</p>
  
  <pre><code>First argument in form cannot contain nil or be empty
  </code></pre></li>
  <li><p>In Safari, when I press the submit button to create a new schedule, the page turns white.  Furthermore, every time I try to go back to the page which displays the form, the page goes white.  It is very strange.  </p></li>
  </ol>
  
  <p>How do I fix this?  Thanks.</p>
  
  <p>UPDATE:  My routes and form view might help:</p>
  
  <p>routes:</p>
  
  <pre><code>resources :projects do
    resources :schedules
  end
  </code></pre>
  
  <p>First part of form:</p>
  
  <pre><code>&lt;%= form_for [@project, @schedule] do |f| %&gt;
  </code></pre>