4 ms·
Good article. A few things: Use "if" and "present?" instead of "unless" and "blank?". It's much easier to parse mentally, especially for people who didn't wri
by getsat 14y ago
Good article. A few things:
Use "if" and "present?" instead of "unless" and "blank?". It's much easier to parse mentally, especially for people who didn't write the code. :)
You don't need to use "self" to access latitude, longitude, updated_at, etc. You only need to use it for assignment.
You don't need to call #to_s on the captured exception. When you interpolate an object into a string, Ruby calls #to_s on the supplied object itself, e.g., "I am an #{Object}".
I'd probably also add a "has_posts" scope to Category and use that instead of the #where call in ApplicationController.
- robotmay 14y agoThanks for the feedback! I'll keep that in mind for the future; it's a bad habit of mine :D I actually didn't realise you only needed that for assignment. That's going to neaten up my code somewhat. I normally don't put .to_s in strings like that, so I'm not entirely sure why I did in that line. Aye, I'd normally use a scope but I figured I'd write it out more verbosely just for clarity :)