2014-11-21 27 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