I have a model, Avatar, which has a few attributes, including original_url, large_url, and thumb_url. I am using transloadit for file uploads, which is why I am storing these images like this.
I also have a method that takes in a few arguments, one of which is a string. Instead of creating multiple methods for each different avatar size, I'd rather create one with an argument of the which attribute to use (ie: original_url, large_url, etc).
def avatar_for(user, img_size, img_url)
url = user.avatar ? user.avatar.img_url : (Identicon.data_url_for user.username, img_size, [238, 238, 238])
image_tag(......)
end
The above img_url, is where I would pass in the specific attribute I wanted to use like this:
= avatar_for(current_user, 250, 'original_url')
However, that returns the error
undefined method `img_url' for #<Avatar:0x007fdc98217948>
How can I take this string and convert it to act as a attribute on an object.