YAML Problem YAML::Object

  • Thread starter Fransiscus Xaverius
  • Start date
F

Fransiscus Xaverius

This was already saved in my database :

c.lawsuit.customer_service_location

=> "--- !ruby/object:Address \nattributes: \n created_on: 2006-02-24
12:30:19 \n city: Alex City\n line1: 441 Saint Bernard Drive\n zip:
\"35086\"\n ''\n id: \"124\"\n contact_detail_id: \"128\"\n detail_key:
Home Address \n state: AL"

AND I DO THIS

=>#<YAML::Object:0xb7986eb8 @class="Address",
@ivars={"attributes"=>{"line1"=>"441 Saint Bernard Drive", "city"=>"Alex
City", "created_on"=>"2006-02-24 12:30:19", "line2"=>"", "zip"=>"35086",
"id"=>"124", "state"=>"AL", "detail_key"=>"Home Address",
"contact_detail_id"=>"128"}}>

PROBLEM
------------------------NoMethodError: Undefined 'city' for #<YAML::Object:0xb7986eb8>
from (irb): 93
from : 0


THE QUESTION
--------------
How I can call city's value like doing below :

call_address = Address.find 128
=> #<Address:0xb79076ac @attributes={"created_on"=>"2006-02-24
12:30:19", "city"=>"Alex City", "line1"=>"441 Saint Bernard Drive",
"zip"=>"35086",
"line2"=>"", "id"=>"124", "contact_detail_id"=>"128",
"detail_key"=>"Home
Address", "state"=>"AL"}>

call_address.city
=> "Alex City"

Thank You
FX
 
Y

yermej

This was already saved in my database :

c.lawsuit.customer_service_location

=> "--- !ruby/object:Address \nattributes: \n created_on: 2006-02-24
12:30:19 \n city: Alex City\n line1: 441 Saint Bernard Drive\n zip:
\"35086\"\n ''\n id: \"124\"\n contact_detail_id: \"128\"\n detail_key:
Home Address \n state: AL"

AND I DO THIS


=>#<YAML::Object:0xb7986eb8 @class="Address",
@ivars={"attributes"=>{"line1"=>"441 Saint Bernard Drive", "city"=>"Alex
City", "created_on"=>"2006-02-24 12:30:19", "line2"=>"", "zip"=>"35086",
"id"=>"124", "state"=>"AL", "detail_key"=>"Home Address",
"contact_detail_id"=>"128"}}>

PROBLEM
------------------------>> my_test.city

NoMethodError: Undefined 'city' for #<YAML::Object:0xb7986eb8>
from (irb): 93
from : 0

THE QUESTION
--------------
How I can call city's value like doing below :

call_address = Address.find 128
=> #<Address:0xb79076ac @attributes={"created_on"=>"2006-02-24
12:30:19", "city"=>"Alex City", "line1"=>"441 Saint Bernard Drive",
"zip"=>"35086",
"line2"=>"", "id"=>"124", "contact_detail_id"=>"128",
"detail_key"=>"Home
Address", "state"=>"AL"}>

call_address.city
=> "Alex City"

Thank You
FX

It should work so long as the environment where you load the YAML has
the correct definition of the Address class. In your first example
(where it isn't working right), you should be able to add something
before your YAML.load like:

require 'address'

where the file address.rb has the class definition of Address. Without
that, Ruby can't actually instantiate the Address class so you just
get the YAML::Object object that you're seeing.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,262
Messages
2,571,052
Members
48,769
Latest member
Clifft

Latest Threads

Top