Skip to content

Instantly share code, notes, and snippets.

@eriknomitch
Last active November 11, 2016 15:28
Show Gist options
  • Save eriknomitch/69b7026ff83ce51914aec27eafb11bd1 to your computer and use it in GitHub Desktop.
Save eriknomitch/69b7026ff83ce51914aec27eafb11bd1 to your computer and use it in GitHub Desktop.
A shorter and cleaner way to render partials in Rails
module ApplicationHelper
# Wraps the commonly used `render partial:` to just `partial`
def partial(path, options={}, &block)
render partial: path.to_s, **options, &block
end
end
<div>
<%# Symbols will work: %>
<%= partial :form, locals: {foo: "bar"} %>
<%# Or, if you need/want a string: %>
<%= partial "shared/header" %>
</div>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment