writing the user_id of user when creating an item

You likely want to do something like this is your controller:

current_user.items.create(params[:item])

This will automatically set the user_id for you.