Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 2nd, 2012  |  syntax: None  |  size: 0.37 KB  |  hits: 9  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. newbie: get attribute value of an object gives error undefined method for #<ActiveRecord::Relation>
  2. @location = Location.where(:id => 1)
  3.        
  4. undefined method `city' for #<ActiveRecord::Relation:0x007ff2d1506330>
  5.        
  6. @location = Location.where(:id => 1).first
  7. # or...
  8. @location = Location.find(1)  # Finds by ID
  9.        
  10. @location = Location.find(1)  # 1 is the id your looking for