I am trying to create a string array inside my model, where I can push new strings (IDs) into the string array - but it's not pushing the correct values.
Here is how the model looks:
class CreateCompanies < ActiveRecord::Migration
def change
create_table :companies do |t|
t.string :name
t.string :email
t.string :users, array: true, default: []
t.timestamps null: false
end
end
end
And here is how I'm adding the new values to the array in the Controller:
c = Company.new
c.users << @user.id
c.save
A value does indeed get added to the array, but it's not the ID but just some random value like this:
users: "--- []\n\u{478A6}"
Been stuck at this for a couple of days now - does anyone know what I'm missing?
UPDATE: Added the code where I create a new Company
def create
@user = User.new(user_params)
if @user.save
@user.id = SecureRandom.random_number(999999)
session[:user_id] = @user.id
c = Company.new
c.id = SecureRandom.random_number(999999)
c.name = @user.company_name
c.email = "email goes here"
c.users << @user.id
c.save
@user.company_id = c.id
@user.save
redirect_to '/dashboard'
else
redirect_to '/'
end
end