title: Rails association for post and location - has_many and belongs_to
body: <p>I am creating a <code>Post</code> model which has one <code>Location</code>. A <code>Location</code> can be in many <code>Post</code>s. For this relationship, I created the field <code>location_id</code> in <code>Post</code>.</p>
  
  <p>I was wondering to do the following belongs_to and has_many:</p>
  
  <pre><code>class Post &lt; ActiveRecord::Base
     attr_accessible :description, :price, :location_id
     belongs_to :location
  end
  
  
  class Location &lt; ActiveRecord::Base
     attr_accessible :latitude, :longitude, :name
     has_many :posts
  end
  </code></pre>
  
  <p>Creating these two models, when I know that I can create a post doing something like:</p>
  
  <pre><code>my_post = my_location.posts.create ....
  </code></pre>
  
  <p>but in my application, people will search about Post description, and in the results it need to show all Post that were found and the name of the Location, like:</p>
  
  <pre><code>Post Description: XXXXXXX
  Location Name: New York
  
  Post Description: YYYYYYY
  Location Name: New York
  
  Post Description: ZZZZZZ
  Location Name: Chicago
  </code></pre>
  
  <p>What is the best way to do this association. As I'm doing, in my Post in only have my location_id and I cant do something like (i got a method missing error)</p>
  
  <pre><code>my_post.location.name
  </code></pre>
  
  <p>I don't think I'm doing right If I need to search for each my_post.location_id, just to get the location name.</p>
  
  <p>This in fact was some stupid mistake that I really don't know what I did, sorry, and thanks for the help</p>