1

if I want to move the following code into helper

      %td.center= log.streaming_verification_id
      %td.center= log.id

and render it by calling call_the_helper

How to write the method call_the_helper to meet my requirement

into helper

  - @tool_cvt_streaming_verification_logs.each do |log|
    %tr
      = call_the_helper
user3675188
  • 7,271
  • 11
  • 40
  • 76

2 Answers2

1

Put something like it in your def call_the_helper:

haml_tag :td, :class => 'center' do
  log.streaming_verification_id
end
haml_tag :td, :class => 'center' do
  log.id
end
Aleksandr K.
  • 1,338
  • 14
  • 21
  • 1
    Nowadays you may need something like `haml_concat log.id` to render the text, but the general approach is still good. – Arsen7 Nov 15 '18 at 10:58
1

Simply to do it by moving the code into an other view (partial), and render it from helper or another view.

view:

- @tool_cvt_streaming_verification_logs.each do |log|
  %tr
    = call_the_helper(log)

helper:

def call_the_helper(log)
    render partial: 'partial_view', locals: { :log => log }
end

partial view:

%td.center= log.streaming_verification_id
%td.center= log.id
Малъ Скрылевъ
  • 16,187
  • 5
  • 56
  • 69