Guest User

Untitled

a guest
Jul 16th, 2018
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.81 KB | None | 0 0
  1. class Membership < ActiveRecord::Base
  2. belongs_to :course
  3. belongs_to :person
  4.  
  5. class Course < ActiveRecord::Base
  6. has_many :memberships
  7. has_many :people, :through => :memberships
  8.  
  9. class Person < ActiveRecord::Base
  10. has_many :memberships
  11. has_many :courses, :through => :memberships
  12.  
  13. form do |f|
  14. f.inputs
  15.  
  16. f.has_many :associations do |association|
  17. association.inputs
  18. end
  19.  
  20. f.buttons
  21. end
  22.  
  23. class Ingredient < ActiveRecord::Base
  24. has_and_belongs_to_many :products, :join_table => :ingredients_products
  25. end
  26.  
  27. class Product < ActiveRecord::Base
  28. has_and_belongs_to_many :ingredients, :join_table => :ingredients_products
  29. end
  30.  
  31. class CreateProductsIngredients < ActiveRecord::Migration
  32. def self.up
  33. create_table :ingredients_products,:id => false do |t|
  34. t.integer :product_id
  35. t.integer :ingredient_id
  36. t.timestamps
  37. end
  38. end
  39.  
  40. def self.down
  41. drop_table :products_ingredients
  42. end
  43. end
  44.  
  45. ActiveAdmin.register Product do
  46. form do |f|
  47. f.inputs "Details" do
  48. f.input :product_name
  49. f.input :brand
  50. f.input :ingredients # don't forget this one!
  51. end
  52. end
  53.  
  54. ActiveAdmin.register User do
  55. index do
  56. column :id
  57. column :name
  58. column :attendance
  59. column :person do |membership|
  60. membership.person.name
  61. end
  62. column :course do |membership|
  63. membership.course.name
  64. end
  65. default_actions
  66. end
  67.  
  68. form do |f|
  69. f.inputs "Membership" do
  70. f.input :name
  71. f.input :created_at
  72. f.input :updated_at
  73. end
  74. f.inputs :name => "Person", :for => :person do |person|
  75. person.inputs
  76. end
  77. f.inputs :name => "Course", :for => :course do |course|
  78. course.input :name
  79. end
  80. f.buttons
  81. end
  82. end
Add Comment
Please, Sign In to add comment