If soil moisture has been uneven, this can trigger the condition. There is no way to fix it but the undamaged parts are safe to eat.
To prevent blossom end rot, dolomite lime can be added to the soil at planting time. Some tomato growers swear by powdered milk, adding a tablespoonful of dry whole-milk powder to the soil around each plant. (I have used it and didn’t get blossom end rot.)
Others recommend a small amount of diluted epsom salts (magnesium sulphate) watered into the tomatoes’ roots during the growing season. This is useful to combat magnesium deficiency, common in glasshouse tomatoes, but would be unlikely to help prevent blossom end rot.