I have object person.=>#<person id: 123, name: "test", sex: "1">
when I check name value in rails 2.0.2
used:
puts person.name
I got this Error:
#<NoMethodError: You have a nil object when you didn't expect it!
You might have expected an instance of ActiveRecord::Base.
The error occurred while evaluating nil.>
I use this way in rails 1.2.6, I can get right value "test"
but when I used:
puts person["name"]
I got the value "test"
So Now I have confused, what happen? Who Can tell me why?
Thanks!
Hi, could you provide a little bit more detail? I’m guessing that
you’re entering that data into a form. Thus, could you provide
the form as well as the processing code? Next, person.name from
the context of the Ruby code should be an instance of Person.rb.
Lastly, if the post variable in your form is name=“person[name]”, then
you can access in the resulting action as follows: