gpt4 book ai didi

ruby-on-rails-3 - 事件管理员 has_many 通过删除关联

转载 作者:行者123 更新时间:2023-12-04 07:19:43 26 4
gpt4 key购买 nike

我目前正在做这样的关联:

show do
h3 project.title
panel "Utilisateurs" do
table_for project.roles do
column "Prenom" do |role|
role.user.firstname
end
column "Nom" do |role|
role.user.lastname
end
column "email" do |role|
role.user.email
end
column "Role" do |role|
role.role_name.name
end
end
end
end

# override default form
form do |f|
f.inputs "Details" do # Project's fields
f.input :title
f.input :code
end

f.has_many :roles do |app_f|
app_f.inputs do
# if object has id we can destroy it
if app_f.object.id
app_f.input :_destroy, :as => :boolean, :label => "Supprimer l'utilisateur du projet"
end
app_f.input :user, :include_blank => false, :label_method => :to_label
app_f.input :role_name, :include_blank => false
end
end
f.buttons
end

我有以下关联:

项目
has_many :roles, :dependent => :destroy 
has_many :users, :through => :role

用户
has_many :roles, :dependent => :destroy
has_many :projects, :through => :role

角色
belongs_to :user
belongs_to :project
belongs_to :role_name

角色名称
has_many :roles

当我试图通过我的表单破坏用户关联时,什么也没有发生,有什么想法可以解决这个问题吗?
或者将删除链接添加到我的节目块?

最佳答案

尝试添加 accepts_nested_attributes_for到您的项目模型(和 roles_attributes 到 attr_accessible):

class Project < ActiveRecord::Base
has_many :roles, :dependent => :destroy
has_many :users, :through => :role
accepts_nested_attributes_for :roles, :allow_destroy => true

attr_accessible :roles_attributes, (+ all you had here before)
...
end

关于ruby-on-rails-3 - 事件管理员 has_many 通过删除关联,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9158727/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com