Use the build method:
user = User.find(1).posts.build(content: "post content")
In the case of a has_one relationship, invoke the build_association method:
user = User.find(1).build_profile(content: "profile content")
In either event, a new child object is initialized and associated to the parent User, however, you'll need to save your User instance in order to preserve the association:
user.save
Alternatively, the same associations can be created via the create and create_association methods:
User.find(1).posts.create(content: "post content")
User.find(1).create_profile(content: "profile content")
Neither call requires that the parent be saved – the associated child is created and saved at the instant that the respective creation method is called.
An important note: both the create and create_association methods are deprecated in Rails 4.