具有 HTML 个标签的助手 Ruby
Helper Ruby with HTML tags
我正在尝试编写一个帮助程序来创建一个可折叠的 Grop。
我转换了
<div class="panel panel-default">
<div class="panel-heading" role="tab" id="headingOne">
<h4 class="panel-title">
<a role="button" data-toggle="collapse" data-parent="#accordion" href="#collapseOne" aria-expanded="true" aria-controls="collapseOne">
Collapsible Group Item #1
</a>
</h4>
</div>
<div id="collapseOne" class="panel-collapse collapse in" role="tabpanel" aria-labelledby="headingOne">
<div class="panel-body">
text to answer
</div>
</div>
到
def faqbox(question, answer, number)
open :div, :class => "panel panel-default" do
open :div, :class => "panel-heading", :role => "tab", :id => "heading#{number}" do
open :h4, :class => "panel-title" do
open :a, :role => "button", :data-toggle => "collapse", :data-parent => "#accordion", :href => "#collapseOne", :aria-expanded => "true", :aria-controls => "collapse#{number}" do
"#{question}"
end
end
end
end
open :div, :id => "collapse#{number}", :class => "panel-collapse collapse in", :role => "tabpanel", :aria-labelledby => "heading#{number}" do
open :div, :class => "panel-body" do
"#{answer}"
end
end
end
但它给我“TypeError at /getting-help
没有将 Symbol 隐式转换为 String
我正在与中间人一起使用 ruby。我做什么骗局?
请考虑使用部分而不是大量嵌套 open
# _faqbox.html.erb
<% heading = "heading#{number}"%>
<% collapse ="collapse#{number}" %>
<div class="panel panel-default">
<div class="panel-heading" role="tab" id=<%= heading %>>
<h4 class="panel-title">
<a role="button" data-toggle="collapse" data-parent="#accordion" href="#<%= collapse %>" aria-expanded="true" aria-controls="<%= collapse %>">
<%= question %>
</a>
</h4>
</div>
<div id="<%= collapse %>" class="panel-collapse collapse in" role="tabpanel" aria-labelledby="headingOne">
<div class="panel-body">
<%= answer %>
</div>
</div>
</div>
# some view
<%= render partial: "faqbox", locals: {question: "foo", answer: "bar", number: 3} %>
结果
我正在尝试编写一个帮助程序来创建一个可折叠的 Grop。 我转换了
<div class="panel panel-default">
<div class="panel-heading" role="tab" id="headingOne">
<h4 class="panel-title">
<a role="button" data-toggle="collapse" data-parent="#accordion" href="#collapseOne" aria-expanded="true" aria-controls="collapseOne">
Collapsible Group Item #1
</a>
</h4>
</div>
<div id="collapseOne" class="panel-collapse collapse in" role="tabpanel" aria-labelledby="headingOne">
<div class="panel-body">
text to answer
</div>
</div>
到
def faqbox(question, answer, number)
open :div, :class => "panel panel-default" do
open :div, :class => "panel-heading", :role => "tab", :id => "heading#{number}" do
open :h4, :class => "panel-title" do
open :a, :role => "button", :data-toggle => "collapse", :data-parent => "#accordion", :href => "#collapseOne", :aria-expanded => "true", :aria-controls => "collapse#{number}" do
"#{question}"
end
end
end
end
open :div, :id => "collapse#{number}", :class => "panel-collapse collapse in", :role => "tabpanel", :aria-labelledby => "heading#{number}" do
open :div, :class => "panel-body" do
"#{answer}"
end
end
end
但它给我“TypeError at /getting-help 没有将 Symbol 隐式转换为 String
我正在与中间人一起使用 ruby。我做什么骗局?
请考虑使用部分而不是大量嵌套 open
# _faqbox.html.erb
<% heading = "heading#{number}"%>
<% collapse ="collapse#{number}" %>
<div class="panel panel-default">
<div class="panel-heading" role="tab" id=<%= heading %>>
<h4 class="panel-title">
<a role="button" data-toggle="collapse" data-parent="#accordion" href="#<%= collapse %>" aria-expanded="true" aria-controls="<%= collapse %>">
<%= question %>
</a>
</h4>
</div>
<div id="<%= collapse %>" class="panel-collapse collapse in" role="tabpanel" aria-labelledby="headingOne">
<div class="panel-body">
<%= answer %>
</div>
</div>
</div>
# some view
<%= render partial: "faqbox", locals: {question: "foo", answer: "bar", number: 3} %>
结果