Rails以文本或标签的形式显示结果,而不是“text_field”,仅允许销毁,不进行更新(Rails display results in form as text or labels instead of “text_field”,allow destroy only, no updates)

我希望能够只创建标签,不进行编辑,但允许销毁。 标签在我的帖子页面上是部分的。 它的工作原理我只是想弄清楚如何将“text_field”中的结果放入标签中。

<%= form.fields_for :tags do |tag_form| %> <div class="field"> <%= tag_form.text_field :tag %> #instead of this I want the result as the label for the destroy textbox. <% unless tag_form.object.nil? || tag_form.object.new_record? %> <%= tag_form.check_box :_destroy %> </div> <% else %> CREATE NEW TAG <% end %> <% end %>

I would like to be able to create tags only, no editing, but allowing destroying. The tags are a partial on my Posts page. It works I just cant figure out how to put the result that is in a "text_field" into a label.

<%= form.fields_for :tags do |tag_form| %> <div class="field"> <%= tag_form.text_field :tag %> #instead of this I want the result as the label for the destroy textbox. <% unless tag_form.object.nil? || tag_form.object.new_record? %> <%= tag_form.check_box :_destroy %> </div> <% else %> CREATE NEW TAG <% end %> <% end %>

最满意答案

尝试这个

<%= tag_form.label :tag, 'TAG LABEL HERE' %>

try this

<%= tag_form.label :tag, 'TAG LABEL HERE' %>Rails以文本或标签的形式显示结果,而不是“text_field”,仅允许销毁,不进行更新(Rails display results in form as text or labels instead of “text_field”,allow destroy only, no updates)

我希望能够只创建标签,不进行编辑,但允许销毁。 标签在我的帖子页面上是部分的。 它的工作原理我只是想弄清楚如何将“text_field”中的结果放入标签中。

<%= form.fields_for :tags do |tag_form| %> <div class="field"> <%= tag_form.text_field :tag %> #instead of this I want the result as the label for the destroy textbox. <% unless tag_form.object.nil? || tag_form.object.new_record? %> <%= tag_form.check_box :_destroy %> </div> <% else %> CREATE NEW TAG <% end %> <% end %>

I would like to be able to create tags only, no editing, but allowing destroying. The tags are a partial on my Posts page. It works I just cant figure out how to put the result that is in a "text_field" into a label.

<%= form.fields_for :tags do |tag_form| %> <div class="field"> <%= tag_form.text_field :tag %> #instead of this I want the result as the label for the destroy textbox. <% unless tag_form.object.nil? || tag_form.object.new_record? %> <%= tag_form.check_box :_destroy %> </div> <% else %> CREATE NEW TAG <% end %> <% end %>

最满意答案

尝试这个

<%= tag_form.label :tag, 'TAG LABEL HERE' %>

try this

<%= tag_form.label :tag, 'TAG LABEL HERE' %>