我遇到许多错误,不确定如何加入content_tags块。
bs_form_builder.rb:36:语法错误,意外的tSYMBEG,预期结束 @ template.content_tag:div,类:“输入组”
bs_form_builder.rb:36:语法错误,意外发生,期望结束... g :div,class:“ input-group” do ... ^〜
bs_form_builder.rb:39:语法错误,意外的“ +”,预期结束 + ^
bs_form_builder.rb:43:语法错误,意外结束,期望 输入结束^ ~~
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>
答案 0 :(得分:0)
需要在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