Where does a comma go when you are using linking words to connect ideas, such as but or and?

A comma is usually placed before the linking word when you are using it to connect two independent clauses. For example: "I wanted to go for a walk, but it started raining."