How to save class as one of the attributes in ROR model

I am trying to create a model in rails named chat, where I have two columns user1 and user2, and I want to store the user object in these. In grails, I do this simply as

class Chat {
  User user1
  User user2
  Date chatStartedOn
}     

and I am done. I did somewhat the same for rails

rails generate model Chat user1:User user2:User chatStartedOn:date                    

but I run db:migrate it showing me the error

undefined method `User' for #<ActiveRecord::ConnectionAdapters::TableDefinition

my user migrate file

class CreateUsers < ActiveRecord::Migration
  def change
    create_table :users do |t|
      t.string :username 
      t.string :email
      t.string :encrypted_password 
      t.string :salt
      t.timestamps
    end
  end 
end

Please guide me on how I save user’s object in chat table.


Source: ruby

Leave a Reply