加入 content_tag 个块(表单生成器)
Joining Blocks of content_tag (Form Builder)
我收到一些错误并且不确定如何加入 content_tags 的块。
bs_form_builder.rb:36: syntax error, unexpected tSYMBEG, expecting end
@template.content_tag :div, class: "input-group" do
bs_form_builder.rb:36: syntax error, unexpected do, expecting end ...g
:div, class: "input-group" do ... ^~
bs_form_builder.rb:39: syntax error, unexpected '+', expecting end end
+ ^
bs_form_builder.rb:43: syntax error, unexpected end, expecting
end-of-input end ^~~
class BsFormBuilder < ActionView::Helpers::FormBuilder
def bs_dollar_input(method, label)
@template.content_tag :div, class: "form-group" do
@template.label(@object_name, label)+
@template.content_tag :div, class: "input-group" do
@template.content_tag :div, class: "input-group-prepend" do
@template.content_tag(:span, "$", class:'input-group-text')
end +
@template.text_field(@object_name, method, class: 'form-control')
end
end
end
end
预期结果:
<div class="form-group">
<label>What is the value of your favorite car?</label>
<div class="input-group">
<div class="input-group-prepend">
<span class="input-group-text">$</span>
</div>
<input class="form-control" id="car" name="car" required="" type="text" value="0" />
</div>
</div>
需要在 content_tags 上添加 ()。
def bs_dollar_input(method, label)
@template.content_tag :div, class: "form-group" do
@template.label(@object_name, label)+
@template.content_tag(:div, class: "input-group") do
@template.content_tag( :div, class: "input-group-prepend") do
@template.content_tag(:span, "$", class:'input-group-text')
end +
@template.text_field(@object_name, method, class: 'form-control')
end
end
end
end
我收到一些错误并且不确定如何加入 content_tags 的块。
bs_form_builder.rb:36: syntax error, unexpected tSYMBEG, expecting end @template.content_tag :div, class: "input-group" do
bs_form_builder.rb:36: syntax error, unexpected do, expecting end ...g :div, class: "input-group" do ... ^~
bs_form_builder.rb:39: syntax error, unexpected '+', expecting end end + ^
bs_form_builder.rb:43: syntax error, unexpected end, expecting end-of-input end ^~~
class BsFormBuilder < ActionView::Helpers::FormBuilder
def bs_dollar_input(method, label)
@template.content_tag :div, class: "form-group" do
@template.label(@object_name, label)+
@template.content_tag :div, class: "input-group" do
@template.content_tag :div, class: "input-group-prepend" do
@template.content_tag(:span, "$", class:'input-group-text')
end +
@template.text_field(@object_name, method, class: 'form-control')
end
end
end
end
预期结果:
<div class="form-group">
<label>What is the value of your favorite car?</label>
<div class="input-group">
<div class="input-group-prepend">
<span class="input-group-text">$</span>
</div>
<input class="form-control" id="car" name="car" required="" type="text" value="0" />
</div>
</div>
需要在 content_tags 上添加 ()。
def bs_dollar_input(method, label)
@template.content_tag :div, class: "form-group" do
@template.label(@object_name, label)+
@template.content_tag(:div, class: "input-group") do
@template.content_tag( :div, class: "input-group-prepend") do
@template.content_tag(:span, "$", class:'input-group-text')
end +
@template.text_field(@object_name, method, class: 'form-control')
end
end
end
end