Rails – Cocoon gem – 嵌套表格
我正在尝试用Rails 4创建一个应用程序。
我为表单使用简单的表单gem,并尝试使用Cocoon gem作为表单的嵌套元素。
我问了这个问题,它解释了我想要更详细地实现的内容: Rails – 单个属性的多个条目
我有个人资料模型和资格模型。 协会是:
profile.rb
has_many :qualifications accepts_nested_attributes_for :qualifications, reject_if: :all_blank, allow_destroy: true
qualification.rb
belongs_to :profile
配置文件控制器包含强参数中的限定属性:
def profile_params params[:profile].permit(:user_id, :title, :hero, :overview, :research_interest, :occupation, :external_profile, :working_languages, :tag_list, qualifications_attributes: [:id, :level, :title, :year_earned, :institution, :_destroy] ) end
我的个人资料表现在有:
Your qualifications