title: Newbie: access attributes of model object
body: <p>I have two model classes: <strong>Cars</strong> and <strong>Customers</strong>,</p>
  
  <p>Model <strong>Cars</strong>:</p>
  
  <pre><code>class car &lt; ActiveRecord::Base
  
    #car has attribute :town_code
  
    has_many :customers
  
  end
  </code></pre>
  
  <p>Model <strong>Customers</strong>:</p>
  
  <pre><code>class customer &lt; ActiveRecord::Base
    # customer has attribute :first_name, :last_name
  
    belongs_to :car
  end
  </code></pre>
  
  <p>In my <strong>controller</strong>, I have the following code:</p>
  
  <pre><code>my_customer = Customer.find_all_by_first_name('John')
  p my_customer.last_name
  p my_customer.car_id
  </code></pre>
  
  <p>But I got <code>no attribute 'car_id'</code> <strong>error</strong>, I also got <code>no attribute 'last_name'</code> <strong>error</strong>.</p>
  
  <p><strong>---Question 1:---</strong></p>
  
  <p>I checked my database, I do have <strong>'car_id'</strong> and <strong>'last_name'</strong> columns on my <strong>customer</strong> table. Why I can not access them in the way how my controller code does?</p>
  
  <p><strong>---Question 2:---</strong></p>
  
  <p>but the code : <code>my_customer.map(&amp;:car_id)</code> is working for accessing car_id, however, I do not quite understand the code <code>.map(&amp;:car_id)</code>, what does it do? Can anyone explains to me?</p>