And in many markets, especially in big expensive cities like NY & SF, it costs more money to buy than to rent.
On the other hand I have family that live in an area where apartment rents are much cheaper than the monthly TCO for buying, and even if you can afford to buy renting makes more sense (unless you need 3-4 bedrooms for a family) because rents are so much cheaper & it is better to put the difference between monthly costs into an index fund and build equity that way.
Another rule you can go with is the Rule of 28 if you prefer. These guidelines exist for a reason. Ignore at your own peril.
Lenders look at these things when considering giving you money. Using more leverage usually gives the bank a better deal than you.
They exist because of the economic context at the time and place that they were generated, which may not have been valid for much more than that immediate context.
If you can find and examine the mathematical assumptions about cost and risk that justify the rule of thumb against current conditions, then you can make an informed evaluation of whether or not it applies to the current situation. If you can’t, like folk remedies, the advice is as likely to harmful as helpful in your actual concrete circumstances.
There is peril in ignoring the specifics of your own individual economic circumstances. If you make $300,000/year and aren't carrying significant other debt then you can afford 4x salary for a $1.2 million house because the ratio of your non-housing expenses do not have to scale upwards with your salary. At 4% interest that's $72k/year, leaving ample room for spending on a comfortable life style while still saving 20% of your salary. In fact that is actually less than your Rule of 28. Alternatively, if you make $300k/year but have $80k in credit card debt and additional business debt made on a personal guarantee then even a 2x house may be too expensive.
Situations vary based on much more complex factors than the salary:$home ratio. Simplistic rules are a greater peril than individual analysis.