Why do I have to access variable using symbol instead of dot operator with
active record
In a model
class Line < ActiveRecord::Base
def location
pkg = PkgLineTree.find_by(pkg_line_id: self.id)
pkg[:tree_id] # works
pkg.tree_id # undefined
end
end
in a Controller
class ApplicationController < ActionController::Base
protected
def lines
line = Line.take
pkg = PkgLineTree.find_by(pkg_line_id: line.id)
ap pkg.tree_id # works
ap pkg[:tree_id] #works
end
end
What's weird is when I call pkg.class in both instances it gives me a
class of PkgLineTree
Thanks for the help!
No comments:
Post a Comment