Last Updated: February 25, 2016
·
746
· mokevnin

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

1 Response
Add your response

I still doesn't see use-case for assignment in view.

over 1 year ago ·