Rails - ActiveResource returning hash instead of an object

1.1k views Asked by At

I've got the following code

u = Client.get(:show_by_username, :username => username.downcase)

When a valid user is returned, they seem to be getting returned as a hash instead of an object that I can call methods on

e.g. I have to access values like

u['id']

instead of

u.id

How can I get it to return it as an object?

Thanks

1

There are 1 answers

0
idlefingers On BEST ANSWER

As described in the docs for the ActiveResource 'get' method, it does not convert them into ActiveResource::Base instances. As it says, you need to use the find method instead:

u = Client.find(:all, :from => :show_by_username, :params => { :username => username.downcase })