So I have created two models:
rails g scaffold user name email
and
rails g scaffold rental_unit address rooms:integer bathrooms:integer price_cents:integer
and defined association as follow:
class RentalUnit < ActiveRecord::Base
belongs_to :user
end
Now, I want to data using rails console as follow:
> user = User.new
> user.name = "John Doe"
> user.email = "test@example.com"
> user.save!
> unit = RentalUnit.new
> unit.address = "abc street"
> unit.rooms = 4
> unit.bathrooms = 2
but I am unable to associate above record using:
unit.user = user
How do I do that in rails console? What is the better way to define this relationship using generators?