Я пытаюсь произвести следующий HTML, используя рельсы хелперы в хелперов файле:рендеринга текста и HTML в блоке content_tag
<span class="btn btn-default btn-file">
Browse File<%= file_field_tag :file %>
</span>
<input type="text" class="form-control file-display" placeholder="" style="width: 250px; display: inline">
Это то, что я пробовал:
def file_helper(form, attr)
span = content_tag :span, class:"btn btn-default btn-file" do
"Browse File" + form.file_field(attr)
end
input = content_tag(:input, nil, type: 'text', class:"form-control file-display", style:"width: 250px; display: inline")
span + input
end
<%= file_helper f, :document %>
К сожалению, в результате HTML выглядит следующим образом:
<span class="btn btn-default btn-file">Browse File<input id="document_document" name="document[document]" type="file" /></span>
<input class="form-control file-display" style="width: 250px; display: inline" type="text">
проблема заключается в вложенной вход диапазона не отображаются как HTML. Он отображается как текст вместе с «Browse File». Как я могу получить «Обзорный файл» для рендеринга в виде текста и ввода для рендеринга как html во внешнем пространстве?