Last active
November 11, 2016 15:28
-
-
Save eriknomitch/69b7026ff83ce51914aec27eafb11bd1 to your computer and use it in GitHub Desktop.
A shorter and cleaner way to render partials in Rails
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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