如何在方法助手中使用条件类?

时间:2016-11-30 14:11:08

标签: html ruby-on-rails class ruby-on-rails-5 helper

我希望在方法助手中有一个条件类

product_helper.rb

CREATE VIEW [dbo].[Summary]
AS
SELECT *
FROM [OriginalSummary] ot
WHERE EXISTS (SELECT 1 FROM [RecordOwner] 
              WHERE [Id] = ot.[MasterId] AND [Owner] = 'corp1')
GO

但是我得到了这个错误:

def product_icon
  ...
  elsif product.sent?
    '<div class="green-text  <%= 'middle' if current_action?(controller: 'products', action: 'index')" %> ><i class="fa fa-envelope-o" aria-hidden="true"></i></div>'.html_safe
end

1 个答案:

答案 0 :(得分:0)

您是帮助者,因此无法使用<%= ... %>但需要使用#{....}

你的助手应该退回:

return "<div class='green-text <%= 'middle' if current_action?(controller: 'products', action: 'index')'%>><i class='fa fa-envelope-o' aria-hidden='true'></i></div>".html_safe