【问题标题】:Adding a div element in rails在rails中添加一个div元素
【发布时间】:2010-12-02 03:37:50
【问题描述】:

我有一个辅助函数

 def link_to_user(text, user, options = {})
options[:class] = options.has_key?(:class) ? "#{options[:class]} user-link" : ""
content_tag :span, :class => :vcard do
  link_to(text, user, options) +
  content_tag(:span, :style => "display: none;", :class => "userbox") do
    content_tag(:span, :class => "fn") do
      content_tag(:span, :class => "given-name") do user.firstname
       end +
      content_tag(:span, :class => "family-name") do #user.lastname 
       end
    end 
  end
end 

结束

现在我正在尝试添加一个 div 元素作为 vcard span 的兄弟元素。我试过了,但我收到了语法错误,意外的'+',期待 kEND (SyntaxError)

请给点建议

【问题讨论】:

    标签: ruby-on-rails


    【解决方案1】:

    你试过了吗:

    @content = content_tag :span, :class => :vcard do
        link_to(text, user, options) +
        content_tag(:span, :style => "display: none;", :class => "userbox") do
          content_tag(:span, :class => "fn") do
            content_tag(:span, :class => "given-name") do user.firstname
            end +
            content_tag(:span, :class => "family-name") do #user.lastname 
            end
          end 
        end
      end
    @content << content_tag(:div, "etc")
    

    【讨论】:

    • @content "display: none;", :class=> "userdetail") 如果我在上面给出的 div 没有隐藏
    【解决方案2】:

    首先,将参数传递给块的语法是

    method_call do |arg|
    

    您缺少管道 (|)

    其次,您缺少end

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-26
      • 2013-04-27
      • 1970-01-01
      相关资源
      最近更新 更多