Assuming you are handling authentication in such a way that you can access the current user by calling the (current_user) method:
def current_user
@current_user || = User.find (session [: user_id])
end
And suppose you have a model that is configured like this:
class User
has_many: posts
end
class Post
belongs_to: user
end
current_user :
current_user.posts.create(params[:post])