开发者

Rails - ActiveResource returning hash instead of an object

I've got the following code

u = Client.get(:show_by_u开发者_StackOverflow社区sername, :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


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 })
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜