× {{alert.msg}} Never ask again
Get notified about new tutorials RECEIVE NEW TUTORIALS

Simplify your Rails app

Max Pleaner
Apr 08, 2016
<p>Rails has "convention over configuration", but like in Ruby, there's always more than one way to do things.</p> <p>How do you make sure that your codebase is easy for a newcomer to navigate?</p> <p>Rails ships with a good amount of boilerplate. It's helpful to be consistent about where you're putting your code. </p> <p>Here's just a few tips:</p> <p>- config/initializers can be used as a generic lib directory since eveything there is autoloaded by default.</p> <p>- try and limit inheritance chains and avoid defining the same method multiple times in a chain.</p> <p>- when possible, use modules instead of inheritance</p> <p>- try not to split up a module into multiple files. use multiple modules instead.</p> <p>- using class methods with an explicit caller makes the code easier to navigate.</p> <p>- if you prefer writing DSL-style code (very concise, lots of abstraction), comment your code very generously to explain what all the magic does. </p> <p>- be aware that using libraries for observers, factories, authentication, etc might actually complicate your code. It's often easier to customize a handmade implementation. </p> <p>- use lots of partials in views</p>
comments powered by Disqus