2

我正在尝试创建类似于此的内容:Using helpers in rails 3 to output html

这是我的助手:

def section_references_to_html (section)
     concat content_tag (:ol, :class => 'sources') do
        section.references.each do |reference|
          concat content_tag (:li,content_tag(:a, reference.text, :src => reference.url))
        end
      end
  end

但它返回各种语法错误:

/~/app/helpers/application_helper.rb:21: syntax error, unexpected ',', expecting ')'
     concat content_tag (:ol, :class => 'sources') do
                             ^
/~/app/helpers/application_helper.rb:21: syntax error, unexpected ')', expecting keyword_end
     concat content_tag (:ol, :class => 'sources') do
                                                  ^
/~/app/helpers/application_helper.rb:22: syntax error, unexpected keyword_do_block, expecting keyword_end
        section.references.each do |reference|
                                  ^
/~/app/helpers/application_helper.rb:23: syntax error, unexpected tIDENTIFIER, expecting keyword_do or '{' or '('
          concat content_tag (:li,content_tag(:a, referen...
                            ^
/~/app/helpers/application_helper.rb:23: syntax error, unexpected ',', expecting ')'
...       concat content_tag (:li,content_tag(:a, reference.tex...
...                               ^
/~/app/helpers/application_helper.rb:23: syntax error, unexpected ')', expecting keyword_end

我在这里做错了什么?也许使用部分会更好。

4

1 回答 1

3

content_tag主要问题是和之间有空格(。试试这个:

def section_references_to_html(section)
  content_tag(:ol, class: 'sources') do
    section.references.each do |reference|
      content_tag(:li, content_tag(:a, reference.text, href: reference.url))
    end
  end
end
于 2013-04-01T12:42:50.593 回答