【发布时间】:2019-04-25 11:20:41
【问题描述】:
class Resume < ActiveRecord::Base
has_many :user_skills, :dependent => :destroy
accepts_nested_attributes_for :user_skills, :allow_destroy => true, :reject_if => :all_blank
end
class UserSkill < ActiveRecord::Base
belongs_to :resume
has_and_belongs_to_many :technologies
end
class Technology < ActiveRecord::Base
has_and_belongs_to_many :user_skills
end
<%= nested_form_for([:student, @resume], validate: true, :html => { :multipart => true, class: "full-width" }) do |f| %>
------------------------------
Resume fields
------------------------------
<h5>User Skills</h5>
<%= f.fields_for :user_skills do |us| %>
<%= us.label :academic_years, "Academic Years" %>
<%= us.text_field :academic_years %>
<%= us.label :professional_years, "Professional Years" %>
<%= us.text_field :professional_years %>
<%= us.fields_for :technologies do |tech| %>
<%= tech.collection_select :name, Technology.all, :id, :name, { prompt: "Select Technology"}, { :multiple => true, :size => 10} %>
<% end %>
<%= us.link_to_remove "Remove", class: "btn btn-small red right" %>
现在我不知道如何在控制器中管理此记录以进行创建和更新,而且我也不知道如何显示此记录...。如果您了解我的问题,那么请为我提供更新和创建恢复控制器的控制器代码,并帮助我显示恢复数据。
【问题讨论】:
标签: ruby-on-rails ruby ruby-on-rails-3 ruby-on-rails-4 ruby-on-rails-3.2