我无法理解我如何能够改变用户的基本技能,在日志中没有错!
我正确地建立了accepts_nested_attributes_for
?
class User < ApplicationRecord
has_many :user_skills
has_many :skills, through: :user_skills
accepts_nested_attributes_for :user_skills
accepts_nested_attributes_for :skills
def primary_skill
skills.find_by(user_skills: { primary: true })
end
end
class Skill < ApplicationRecord
validates :title, presence: true, uniqueness: true
has_many :user_skills
has_many :users, through: :user_skills
end
class UserSkill < ApplicationRecord
belongs_to :skill
belongs_to :user
accepts_nested_attributes_for :skill
accepts_nested_attributes_for :user
end
什么应该是变革的形式
= simple_form_for @user, url: dashboard_user_url, method: :put do |f|
= f.input :primary_skill, collection: Skill.all, include_blank: false
= f.submit