I am sending object friend through params[:invitations][:friend]. In my params looks like:#< User:0x6925800>. Can I convert this string to an object in my controller?
Why I am sending an object through params? Because I get it from a javascript function that triggers when a field in my dropdown menu is clicked. And if I try to send just an Id(friend.id) of my object rails gives me an error stack too deep.
I googled around but found nothing how to convert string to object so any answers would be greatly appreciated.
So my question remains how can I convert my string(of an object) to an actual object in my controller?
Thing you are asking about is called serialization.
You can use it, but you shouldn’t. Serialization may be good for caching purposes, but in most cases, if you need it – you do something wrong. Just pass an id to script and retrieve data again.
What you’ve got
#< User:0x6925800>is not serialized object, it contains only class name and memory address, so it can’t be unserialized.