let do it
You know, assignments in rails templates is bad practice. But sometimes we need it. For example:
- data = yield :header
- if data.present?
%h3= data
In fact, we can do it better:
- let yield :header do |data|
- if data.present?
%h3= data
Inside 'let':
# application_helper.rb
def let(value)
yield value
end
It is extremely simple
Written by Mokevnin Kirill
Related protips
1 Response
I still doesn't see use-case for assignment in view.
over 1 year ago
·
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Rails
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#