0
이전 프로그램을 haml로 변환하고 있습니다. 사용자 정의 formbuilder에 문제가 있습니다. 문제는 단순히 필드 레이블과 입력 태그 사이에 줄 바꿈을 추가하는 것입니다. 내가 그 < BR/>가 전혀 작동하지 않는 %의 BR을 사용하는 경우haml formbuilder
# Custom FormBuilder
class SuperFormBuilder < ActionView::Helpers::FormBuilder
# Create an array of helpers to override with our label builder
helpers = field_helpers +
%w{calendar_date_select date_select datetime_select time_select} +
%w{collection_select select country_select time_zone_select} -
%w{hidden_field label fields_for} # Don't decorate these
helpers.each do |name|
define_method(name) do |field, *args|
# Get the hash option (EG the field involved)
options = args.extract_options!
# Create a label for that field
label = label(field, options[:label], :class => options[:label_class])
# Create an inline error
error = error_message_on(field)
# Wrap label in paragraph, include the original helper EG: text-field
@template.content_tag(:p, label + "<br />" + super + error) #wrap with a paragraph
end
end
# Override the submit button
def submit
# Calculate custom text for submit button.
prefix = object.new_record? ? "Create" : "Update"
# Wrap submit button in paragraph tags and add custom text.
@template.content_tag(:p,super(prefix, :id => "apply"))
end
end
:
여기에 원래 FormBuilder입니다. 이것을 haml로 바꿀 수있는 방법이 있습니까?
작동 : (: P, 라벨 + @ template.tag ("BR") + 슈퍼 + 오류) template.content_tag @ 는 방법이 있나요 조금만 최소화 하시겠습니까? – map7
@ map7 "concat"을 사용할 가능성이 아직 8 년 후에 있습니다. – Felix