dimanche 28 juin 2015

how to save class as one of attribute in ROR model

so here is very small help i need for ROR , since i m a newbie in rails community. i m trying to create a model in rails named chat where i have two columns user1 and user2 , 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 m done , i did somewhat 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 how do i save users object in chat table.. help !

Aucun commentaire:

Enregistrer un commentaire