title: How do I create the view for the has_one association?
body: <p>So, imagine I have this model:</p>
  
  <pre><code>class Car
    has_one :engine
  end
  </code></pre>
  
  <p>and the engine model:</p>
  
  <pre><code>class Engine
    belongs_to :car
  end
  </code></pre>
  
  <p>When I present the form for the user, so that he can create a new car, I only want to allow him to select from one of the available engines ( the available engines will be in a <code>select</code>, populated by the <code>collection_select</code> ). The thing is, if I build the field like this:</p>
  
  <pre><code>&lt;%= f.collection_select :engine,Engine.all,:id,:name %&gt;
  </code></pre>
  
  <p>When I will try to save it, I will get an AssociationTypeMismatch saying that it expected an Engine, but it received a string. </p>
  
  <p>Is this the way to do it?</p>
  
  <pre><code>def create
    car = Car.new(params[:car])
    engine = Engine.find(params[:engine])
    car.engine = engine
    if car.save
       # redirect somewhere
    else
       # do something with the errors
    end
  end
  </code></pre>
  
  <p>I always felt that stuff, like associating an engine to a car, are done automatically by Rails, but I don't know how to make him do it.</p>
  
  <p>Is switching the <code>has_one</code> and <code>belongs_to</code> associations the only way to achieve this? </p>
  
  <p>I am lost and I feel like I'm missing something very basic here.</p>