DEV Community

Discussion on: Seeding your rails database using Faker

Collapse
 
danimal92 profile image
Daniel Zaltsman • Edited

The only datatype attributes that a rails model accepts is:
:binary
:boolean
:date
:datetime
:decimal
:float
:integer
:bigint
:primary_key
:references
:string
:text
:time
:timestamp

If you needed to attach a profile image to each user, I would recommend hosting/using an image online and attaching the url as a string to the user as an attribute. But, as far as I know, you can't attach the actual file to the user model. But when you're loading the profile picture, you can use the link to load it. You'll have to change your createusers migration file to store the url, drop the table, create the table, and migrate again. So to change the file, it might look something like this:

class CreateUsers < ActiveRecord::Migration[6.0]
  def change
    create_table :users do |t|
      t.string :name
      t.string :profile_url
      t.timestamps
    end
  end
end

Afterwards, delete your schema if you have one, and run rails db:drop && rails db:create && rails db:migrate in the console. Now you can store the url in that string and use it to populate the profile picture area.