1

내가 연결하는 시도하고 같은 content_tag 및 safe_concat, 뭔가를 사용하여 여러 태그 :safe_concat을 사용하여 여러 content_tags를 만드는 방법은 무엇입니까?

content_tag(:select, multiple: "multiple", :name => "contact[resources]") do 
    content_tag(:optgroup, label: "LABEL", id: "some-id") do 
     safe_concat(
     if condition1 
      (content_tag(:option, value: "val1") { "Val1" }) 
     end 
     if condition2 
      (content_tag(:option, value: "val2") { "Val2" }) 
     end    
    ) 
    end     
    end 

하지만 다음과 같은 오류가 계속 : 당신이 safe_concat에있는 모든 단일 출력을 포장 할 필요가

syntax error, unexpected keyword_if, expecting ')' 
syntax error, unexpected end-of-input, expecting keyword_end 

답변

1

을, like

content_tag(:select, multiple: "multiple", :name => "contact[resources]") do 
    content_tag(:optgroup, label: "LABEL", id: "some-id") do 
    if condition1 
     safe_concat(content_tag(:option, value: "val1") { "Val1" }) 
    end 
    if condition2 
     safe_concat(content_tag(:option, value: "val2") { "Val2" }) 
    end    
    end     
end 
+0

정확히 무엇을 찾고 계십니까? –