Open baxter2 opened 1 year ago
Hello, I'm new around here. What do you think about to use the same Rails Satus code? https://gist.github.com/mlanett/a31c340b132ddefa9cca
I'm on the fence for helper methods. I like them but it also could collide with the underlying response that is being delegated to normally. I don't like underscore prefixed, but the methods from that gist seem do-able. Not sure how often most of them would get used as I assume people wouldn't remember what method name matches to what status code.
While working on a project, I often encountered scenarios where I was checking the response code to handle specific HTTP status codes. For instance:
This made me think about the readability and expressiveness of the code. The standard approach,
res.code == 401
, gets the job done, but I wondered if we could introduce helper methods like_401?
to make this even clearer.With the proposed change, the above example could look like this:
I understand that in Ruby, methods can't begin with a number, so I've prefixed it with an underscore. I know this might not be everyone's favorite syntax, so I'm very open to feedback or alternative naming suggestions.
Why is this beneficial?