我的 ruby 应用程序中未定义的方法“关联”

undefined method `association' in my ruby app

在我的 ruby 申请中,我试图将我的 table "events" 与“校园”table 相关联。在使用时 f.association 给出了这个错误:

undefined method 'association' for # < ActionView::Helpers::FormBuilder:0xbbcdbd68 >

遵循我的代码。可以帮我弄清楚我做错了什么吗?谢谢你

class Evento < ActiveRecord::Base
  has_attached_file :foto
  validates_attachment_content_type :foto, :content_type => %w(image/jpeg image/jpg image/png image/gif)
  validates :nome, presence: true
  validates :descricao, presence: true
  validates :local, presence: true
  belongs_to :campu
end

class Campu < ActiveRecord::Base
  validates :nome, presence: true
  has_many :eventos
end

  <div class="field">
    <%= f.label :campu %><br>
    <%= f.association :campu %>
  </div>

f 对象没有关联方法,请参阅文档了解可用方法:

http://api.rubyonrails.org/classes/ActionView/Helpers/FormHelper.html

假设您想使用关联创建一个字段,您必须使用指定字段的方法,例如

<div class="field">
  <%= f.label :campu %><br>
  <%= f.text_field :campu %>
</div>