title: Populating a Select with Model Data in Rails
body: <p>I feel the need to apologize for asking such a simplistic question, but I'm getting increasingly frustrated with the Rails Guides. I'm sure they answer my question, but they don't provide enough context for me to really understand how to <em>apply</em> what they're giving me. Nor is Google much help, though I may just be searching the wrong terms/phrases. Given that disclaimer, I'm just going to go ahead and ask:</p>
  
  <p>I have an <code>Image</code> that HABTM <code>Album</code>. To support that, I have an <code>albums_images</code> table with <code>image_id</code> and <code>album_id</code> fields (no others). For the life of me, I can't figure out how to populate my image form partial so that the user can select the albums a newly uploaded image should belong to.</p>
  
  <p>I'm learning Rails, so I really just want the basics. I'm sure there are fancy plugins to do this a hundred ways, but I'd like to learn the basics first and build from there. My form partial is pretty much textbook:</p>
  
  <pre><code>&lt;% form_for( @image, :html =&gt; { :multipart =&gt; true } ) do |f| %&gt;
    # All the basics you'd expect to see.
  &lt;% end %&gt;
  </code></pre>
  
  <p>My most recent attempt doesn't work any better than any other variation I've tried, but it looks like this:</p>
  
  <pre><code>&lt;p&gt;
    &lt;%= f.label :album_id %&gt;
    &lt;%= f.select( :album_id, current_user.albums, :id, :name ) -%&gt;
  &lt;/p&gt;
  </code></pre>
  
  <p>Again, I recognize the simplicity of the question I'm asking and I've read what I can find, but I haven't been able to put it together into a complete solution. There seem to be many ways to do it, but no real discussion of each one, their pros/cons or how to really use them in a larger context.</p>
  
  <p>Thanks.</p>
  
  <p><strong>UPDATE:</strong> A couple of keys to note and a code correction. First, there's a HABTM relationship between images and albums. Neither model table has a FK directly referencing the other. Second, the album collection should be accessed as <code>current_user.albums</code> (corrected above). A user <code>has_many</code> albums and an album <code>belongs_to</code> user.</p>
  
  <p><strong>UPDATE:</strong> At the request of theIV below, at the moment, with this code: </p>
  
  <pre><code>22: &lt;p&gt;  
  23:   &lt;%= f.label :album_id %&gt;  
  24:   &lt;%= f.select( :album_id, current_user.albums.collect {|a| [a.name, a.id]}) -%&gt;  
  25: &lt;/p&gt;
  </code></pre>
  
  <p>I get this error:</p>
  
  <pre><code>undefined method `album_id' for #&lt;Image:0x1042ec110&gt;
  </code></pre>
  
  <p>I get the error in line 24. </p>