I can't seem to get a has\_one relationship with accepts\_nested\_attributes\_for to work. This is my first foray into nested attributes, so it might be incorrect. Help!

Models:

```
class Case < ActiveRecord::Base
  has_one :logged_event, class_name: 'Event', dependent: :destroy
  accepts_nested_attributes_for :logged_event
end

class Event < ActiveRecord::Base
  belongs_to :case
  belongs_to :user
  validates :case, presence: true
  validates :user, presence: true
end

```

Controller:

```
class CasesController < ApplicationController
  load_and_authorize_resource

  def new
    @case.build_logged_event(user: current_user)
  end

  def create
    if @case.save
      flash[:notice] = 'Case was successfully logged.'
      redirect_to cases_path
    else
      render 'cases/new'
    end
  end
end

```

Form:

```
<h1>New Case</h1>
<%= error_messages_for :case %>
<%= form_for(@case) do |form| %>
  <p>
    <%= form.label(:study) %>:
    <%= form.select(:study, Case.options_for(:study), include_blank: true) %>
  </p>
  <%= form.fields_for(:logged_event) do |logged_event_form| %>
    <%= logged_event_form.label(:created_at, 'Date Case was opened:') %>
    <%= logged_event_form.select(:created_at, [['Today', Date.today], ['Yesterday', Date.yesterday]]) %>
  <% end %>    
  <%= form.submit('Log Case') %> or <%= link_to('cancel', cases_path) %>
<% end %>

```

It's saying that the logged event is not getting a user id or a case id, so both validations on the event class are failing. It looks like:

There were problems with the following fields:  

Logged event case can't be blank  

Logged event user can't be blank

I don't get that, because in the new action I have already built the object. I also tried `form.fields_for(:logged_event, @case.logged_event)` but that didn't work either.