Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 2nd, 2012  |  syntax: None  |  size: 1.42 KB  |  hits: 106  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Active admin has_many through delete association
  2. show do
  3.   h3 project.title
  4.   panel "Utilisateurs" do
  5.     table_for project.roles do
  6.       column "Prenom" do |role|
  7.         role.user.firstname
  8.       end
  9.       column "Nom" do |role|
  10.         role.user.lastname
  11.       end
  12.       column "email" do |role|
  13.         role.user.email
  14.       end
  15.       column "Role" do |role|
  16.         role.role_name.name
  17.       end
  18.     end
  19.   end
  20. end
  21.  
  22. # override default form
  23. form do |f|
  24.   f.inputs "Details" do # Project's fields
  25.     f.input :title
  26.     f.input :code
  27.   end
  28.  
  29.   f.has_many :roles do |app_f|
  30.     app_f.inputs do
  31.       # if object has id we can destroy it
  32.       if app_f.object.id
  33.         app_f.input :_destroy, :as => :boolean, :label => "Supprimer l'utilisateur du projet"
  34.       end
  35.       app_f.input :user,      :include_blank => false, :label_method => :to_label
  36.       app_f.input :role_name, :include_blank => false
  37.     end
  38.   end
  39.   f.buttons
  40. end
  41.        
  42. has_many :roles, :dependent => :destroy
  43. has_many :users, :through => :role
  44.        
  45. has_many :roles, :dependent => :destroy
  46. has_many :projects, :through => :role
  47.        
  48. belongs_to :user
  49. belongs_to :project
  50. belongs_to :role_name
  51.        
  52. has_many :roles
  53.        
  54. class Project < ActiveRecord::Base
  55.     has_many :roles, :dependent => :destroy
  56.     has_many :users, :through => :role
  57.     accepts_nested_attributes_for :roles, :allow_destroy => true
  58.  
  59.     attr_accessible :roles_attributes, (+ all you had here before)
  60.     ...
  61. end