I want do this:
sender_email = @request.user.paypal_email if @request.user.paypal_email == "paypal@anonymous.com"
So basically I want to only execute the command if the users paypal email is "paypal@anonymous.com". This works fine but it seems like there is room for refactoring.
Since this code is in your controller, then it can definitely be refactored. You typically want logic like this to be in the models since it’s easy to write unit tests and it’s not the job of the controller to know so much about the user model.
There’s a few ways you could refactor this, but I would recommend moving the logic to the user model like so:
Then your controller wouldn’t need to know as much and could just do: