logger.info “Org found. Id = #{@org.id}”
Thanks for the help to both responders. There’s something I still don’t
understand tho because attempts to access @org as an array fail for me.
==== code ======
sSQL = "SELECT id, org_name FROM organizations WHERE user_id =
‘#{sUserId}’ AND user_password = ‘#{sPassword}’"
write_log(sSQL)
@org = Organization.find_by_sql(sSQL).first
if @org.nil?
write_log(“Org is nil”)
else
write_log("Org list returned: " + @org.inspect)
end
================
Results in log:
SELECT id, org_name FROM organizations WHERE user_id = ‘kevin’ AND
user_password = ‘password’
Org list returned: #<Organization:0x38130e0 @attributes={“id”=>“1”,
“org_name”=>“Carlie Couches”}>
===============
When I try to access @org.id, however, I get errors.
For instance, this line:
write_log(“Org list returned: #{@org.id}”)
throws this error:
Called id for nil, which would mistakenly be 4 – if you really
wanted the id of nil, use object_id
This line:
write_log(“Org list returned: #{@org.org_name}”)
throws the same error.
This line:
write_log(“Org list returned: #{@org[0].org_name}”)
throws this error:
You have a nil object when you didn’t expect it!
The error occured while evaluating nil.org_name
I’ve looked at it with inspect and to_xml and there is always data
there.
How do I get to it? I’m missing something basic here.
Thanks for helping,
Michael
P.S. I couldn’t figure out how to pass quoted strings as parameters,
that’s why i’m using the sSQL statement instead of parameters. Any
example of passing a quoted string using the ? parameter method would be
helpful too. Passing the strings without accounting for the quotes gave
SQL syntax errors because of empty strings coming through.