0

I am creating a Ruby on Rails website. The users can have avatars from a limited set of avatars I provide, like turntable.fm. and again like Turntable.fm depending on the uses rank they can pick different avatars from different levels.

I am thinking of creating the avatar with scaffold, so have an MVC for it.

rails generate scaffold avatar file_name:string, level:integer

(for non ruby experts ;) ) So my avatar mysql table would have id, file_name and level as it's columns.

and also add a avatar_id to the User table.

I am wondering is this the right way to address this problem? I was just reading about BLOB and storing images in the database, do I need to do anything like that?

Thanks! Mina

Matilda
  • 1,708
  • 3
  • 25
  • 33
  • 1
    There are several questions kicking around about storing images in the database; the general consensus is "don't do it unless you have to". – mu is too short Aug 28 '11 at 08:31

2 Answers2

1

It depends on how many avatar images you have, if they are not tens of thousand or more doing it the way you suggest should be ok, otherwise make sure you read this question.

Then another question is, do you want to have it future proof just in case the requirements change in a big way, for instance in order to support custom avatars. In this case you would probably need something more in the table, say the path to the directory the file will get saved in.

Also it's disputable whether you need a file_name column for this, you could just as well use avatar_id as a filename. Maybe you'll need a name/label for the avatar, but it is not required to name the file like that, and it's best not to actually do it (thinking about i18n over here, special characters but not only that)

Then as already mentioned, you could try save the file itself in the database if you think there are any advantages to it (I wouldn't do it myself, but there are valid pro arguments for going this way, see here for a discussion on the subject)

Community
  • 1
  • 1
Marius Burz
  • 4,555
  • 2
  • 18
  • 28
0

Use carrierwave. It's extremely simple to use and very powerful.

lucapette
  • 20,564
  • 6
  • 65
  • 59
  • I meant more about designing around already existing Avatars, so we don't want to let users to 'upload' their own images. – Matilda Aug 28 '11 at 20:10