-1

I'm trying to generate default images on my database directly on a migration from images included in my rails app (assets/images).

Before this kind of migration, I tap my command directly on the terminal.

I would like something like that :

File.new('path/to/my/default/avatar')

I tried with ActionController::Base.helpers.asset_path, asset_path, Rails.root.join.

If this way is not at all the good one to do what I want, please let me know the best way. :-)

brcebn
  • 1,571
  • 1
  • 23
  • 46

1 Answers1

0

Not sure exactly what you are trying to achieve but you might want to use something like paperclip so that you can upload images to you models.

You may also want to use a seed file to add images to your database as migrations should generally be concerned with changes in the database structure rather than actual data.

Tom Kadwill
  • 1,448
  • 3
  • 15
  • 21
  • I'm using [CarrierWave](https://github.com/carrierwaveuploader/carrierwave) to upload images but now I'm just tying to add default avatar (only once) on my database as I've created some users (that's to say in a migration). But maybe it's not the best way to do it. – brcebn Apr 16 '14 at 08:06
  • I would recommend adding a default image in a seed file. Alternatively it might be a better idea to set the default image in your application code. CarrierWave probably deals with that - try search the readme for setting a default. – Tom Kadwill Apr 16 '14 at 08:11
  • I didn't know the existence of `seed`. It seems better that my first idea. Thank you. – brcebn Apr 19 '14 at 11:25