2014-11-21 24 views
0

如果我想通過調用call_the_helper如何提取HAML代碼到輔助

怎樣寫方法call_the_helper,以滿足我的要求,下面的代碼轉移到輔助

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

,並使其

成幫手

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

回答

1

只需由碼移動到其它視圖(部分)這樣做,並從輔助或另一視圖呈現它。

視圖:

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

助手:

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

局部視圖:

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

把東西像它在def call_the_helper

haml_tag :td, :class => 'center' do 
    log.streaming_verification_id 
end 
haml_tag :td, :class => 'center' do 
    log.id 
end