devalot/ror-example — Issue #1: Adhere better to established conventions
Author: stouset
Created: 2011-11-09 14:39:46+00:00
State: open

If you're making a tutorial app for newcomers, you should stick to the best practices and conventions agreed upon by the Rails and Ruby community (unless you have an explicit, intentional reason not to do so for certain cases).

A few things I noticed off the bat. You use a `before_filter` to set instance variables inside a [controller](https://github.com/devalot/ror-example/blob/master/app/controllers/refuels_controller.rb). This is generally bad practice — the folks at Rails Best Practices have highly downvoted a recommendation to do [exactly that](http://rails-bestpractices.com/posts/22-use-before_filter). My personal recommendation is in the comments of that post, but it boils down to: the contract between controller and view is instance variables. Contract fulfillment should be explicit.

Instead, define (memoized, ideally) a method that returns the collection object, and a method that returns the individual object (chained off the collection). Use these methods in the actions, and assign their return value to the expected instance variable.

Lastly, this is a minor nitpick, but you tend to overuse parentheses — for instance, around every call to `validates`, `has_many`, `belongs_to`, etc. in your models. This style is almost completely nonexistent in the greater community.

Again, there are very minor nitpicks. Were this your personal Rails application, it's of no issue what particular coding conventions you choose to use. However, when writing guides for newcomers, I firmly believe that one should attempt to advocate the conventions of the community as a whole. Any deviation that one feels is necessary or a clear improvement over the existing convention should be documented and explained.

Feel free to shitcan this issue if you disagree with that premise. I encourage you to give it some thought, though.