devalot / ror-example Goto Github PK
View Code? Open in Web Editor NEWSelf-guided Ruby on Rails 3.1 Tutorial
Home Page: http://www.devalot.com/articles/2011/11/ror-example
License: The Unlicense
Self-guided Ruby on Rails 3.1 Tutorial
Home Page: http://www.devalot.com/articles/2011/11/ror-example
License: The Unlicense
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. This is generally bad practice โ the folks at Rails Best Practices have highly downvoted a recommendation to do exactly that. 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.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.