为什么我的文本框以表格形式显示ActiveRecord_Associations_CollectionProxy [英] Why my textbox shows ActiveRecord_Associations_CollectionProxy in form
问题描述
我正在构建Rails应用程序,并使用 form_for
呈现表单。一切工作正常,除了一个文本字段在文本内部具有 ActiveRecord_Associations_CollectionProxy
之外,我不确定它来自哪里。
I'm building rails application and I use form_for
to render the form. Everything works fine works fine except one text field has ActiveRecord_Associations_CollectionProxy
inside the text which I'm not sure where it's coming from.
这是我的表单
<%= form_for(@video, html: { class: "directUpload" }, multipart: true) do |f| %>
<% if @video.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(@video.errors.count, "error") %> prohibited this user from being saved:</h2>
<ul>
<% @video.errors.full_messages.each do |message| %>
<li><%= message %></li>
<% end %>
</ul>
</div>
<% end %>
<div class="field">
<%= f.label :title %><br>
<%= f.text_field :title %>
</div>
<div class="field">
<%= f.label :path %><br>
<%= f.file_field :path%>
</div>
<div class="field">
<%= f.label :tags %><br>
<%= f.text_field :tags %>
</div>
<div class="actions">
<%= f.submit %>
</div>
<% end %>
这是我的视频
模型
class Video < ActiveRecord::Base
belongs_to :user
has_many :video_tags
has_many :tags, through: :video_tags
end
这是屏幕截图
推荐答案
您要在表单中显示多个标签。您的控制器可以为表单提供所有标签,您可以在其中使用 http://apidock.com来显示它们/ rails / ActionView / Helpers / FormOptionsHelper / options_from_collection_for_select 。
You have multiple tags that you want show in form. Your controller could serve all tags for form where you could show them with http://apidock.com/rails/ActionView/Helpers/FormOptionsHelper/options_from_collection_for_select for example.
这篇关于为什么我的文本框以表格形式显示ActiveRecord_Associations_CollectionProxy的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!