Last active
December 26, 2015 07:59
-
-
Save panych/7118574 to your computer and use it in GitHub Desktop.
Block alias in Ruby on 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
# application_helper.rb | |
def b(block_name, options={}, &block) | |
options.merge!(:body => capture(&block)) if block_given? | |
render :partial => block_name, :locals => options | |
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
<!-- Usage: --> | |
<!-- home/index.html.erb --> | |
<%= b 'nav', :items => @nav_items %> | |
<%= b 'article' do %> | |
<h1>Title</h1> | |
<p>lorem</p> | |
<% end %> | |
<!-- old style --> | |
<%= render :partial => 'nav', :locals => { :items => @nav_items } %> | |
<%= render :layout => 'article_old' do %> | |
<h1>Title</h1> | |
<p>lorem</p> | |
<% 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
<article> | |
<%= body %> | |
</article> |
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
<article> | |
<%= yield %> | |
</article> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment