Skip to content

Instantly share code, notes, and snippets.

@andreimoment
Created January 22, 2016 21:00
Show Gist options
  • Save andreimoment/80bcbde434c428fff291 to your computer and use it in GitHub Desktop.
Save andreimoment/80bcbde434c428fff291 to your computer and use it in GitHub Desktop.
Ernie Miller's recommendation for application.rb
# config/application.rb
# published at https://ernie.io/2015/06/16/rails-application-rb-recommendations/
config.generators do |g|
g.assets = false # stop creating empty asset files for every controller you generate
g.helper = false # stop creating empty helper files
end
config.action_controller.include_all_helpers = false # only include this controller's helpers, do not include all others
config.active_record.schema_format = :sql # prevent loss of clarity caused by the lossy schema format
@andreimoment
Copy link
Author

And an interesting comment on Ernie's post:

Kenn Ejima:

I have a different view about include_all_helpers. I turn off generators like you but keep include_all_helpers=true.

I would say instead: Stop creating per-controller helpers. Create helpers to group related methods. I have FlashHelper, AnalyticsHelper, FormHelper, LinkHelper, DisplayHelper, CurrencyHelper, MailerHelper, etc. and those helpers are used in any controllers / views, including layouts.

I even have ControllerHelper to expose small number of view-related methods available in both controllers and views, using "include ControllerHelper" in ApplicationController (directly putting view methods in ApplicationController felt wrong), and MailerHelper is used by "BaseMailer < ActionMailer::Base" which has "helper :mailer". Helpers can include other helpers, so it's easy to nest / group / reuse by meaningful helper module names. In my case, MailerHelper includes LinkHelper and CurrencyHelper.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment