Skip to content

Instantly share code, notes, and snippets.

@henrik
Last active December 19, 2017 11:39
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save henrik/6bb7d8cb06dd89c48b00 to your computer and use it in GitHub Desktop.
Save henrik/6bb7d8cb06dd89c48b00 to your computer and use it in GitHub Desktop.
Convenient `locals` renderer for Rails. Don't use ivars if you can help it. http://thepugautomatic.com/2013/05/locals/
class ApplicationController < ActionController::Base
# stuff
private
# These groups are equivalent:
#
# render action: :new, locals: { item: x }
# render :new, locals: { item: x }
# locals :new, item: x
#
# render locals: { item: x }
# locals item: x
#
def locals(action = nil, hash)
render action: action, locals: hash
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment