I think that this should be:

`- rating = current_user.ratings.where(post: post).first || current_user.ratings.build`

That will allow you to combine the two cases below into a single set of forms.