Saturday, August 13, 2016

rails generator for model with belongs_to

Comment belongs to a user.

rails g model comment content:text user:references

This command will automatically add the belongs_to in comment model. If you generate the model like this:

rails g model comment content:text user_id:integer

Rails will not add the belongs_to to the comment model. You have to do it manually.

No comments:

Post a Comment