Awe*_*wea 7 has-many-through ruby-on-rails-3 activeadmin
我目前正在制作这样的协会:
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
Run Code Online (Sandbox Code Playgroud)
我有以下协会:
项目
has_many :roles, :dependent => :destroy
has_many :users, :through => :role
Run Code Online (Sandbox Code Playgroud)
用户
has_many :roles, :dependent => :destroy
has_many :projects, :through => :role
Run Code Online (Sandbox Code Playgroud)
角色
belongs_to :user
belongs_to :project
belongs_to :role_name
Run Code Online (Sandbox Code Playgroud)
ROLENAME
has_many :roles
Run Code Online (Sandbox Code Playgroud)
当我试图通过我的表单破坏用户关联什么都没发生时,有什么想法来解决这个问题?或者添加删除链接到我的show块?
alo*_*ony 16
尝试添加accepts_nested_attributes_for到您的项目模型(和roles_attributesattr_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
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3872 次 |
| 最近记录: |