lundi 11 janvier 2016

How to add new record to another table created within the same model on Rails console?

I have created a model using this command

rails g model UserPost postId:string postDesc:string

than after I created another table with

rails g migration CreateUser name:string email:string

So, running rails console, I was only able to add records on user_posts table with for example

user=UserPost.create(post_id:"My Post", post_desc:"This is my post")

My question is to know how to add new records on user table? With Sql, this is done using table_name as

INSERT INTO TABLE user_posts values("My Post", "This is my post")

and

INSERT INTO TABLE user values("my_name", "my_email")

but on Rails, I think it uses model's name.

Note: rake db:migrate has been run at its specific time.

Aucun commentaire:

Enregistrer un commentaire