Advertisement
Guest User

Untitled

a guest
Apr 20th, 2014
33
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.93 KB | None | 0 0
  1. class Gallery < ActiveRecord::Base
  2. belongs_to :category
  3. has_many :gallery_images, dependent: :destroy
  4. accepts_nested_attributes_for :gallery_images, allow_destroy: true
  5. end
  6.  
  7. class GalleryImage < ActiveRecord::Base
  8. belongs_to :gallery
  9. belongs_to :gallery_category
  10. end
  11.  
  12.  
  13. class GalleryCategory < ActiveRecord::Base
  14. has_many :gallery_images
  15. end
  16.  
  17. <% for image in @gallery.gallery_images %>
  18. <li><%= image_tag(image.photo.url(:gallery_flexslider)) %>
  19. <p class="flex-caption"></p>
  20. </li>
  21. <% end %>
  22.  
  23. <p class="flex-caption"></p>
  24.  
  25. <% @gallery.gallery_images.each do |image| %>
  26. <li><%= image_tag(image.photo.url(:gallery_flexslider)) %>
  27. <p class="flex-caption"><%= image.gallery_category.name %></p>
  28. </li>
  29. <% end %>
  30.  
  31. <% @gallery.gallery_images.each do |image| %>
  32. <li>
  33. <%= image_tag(image.photo.url(:gallery_flexslider)) %>
  34. <% image.gallery_categories.each do |c| %>
  35. <p class="flex-caption"><%= c.name %></p>
  36. <% end %>
  37. </li>
  38. <% end %>
  39.  
  40. #app/models/image.rb
  41. Class Image < ActiveRecord::Base
  42. has_many :gallery_images
  43. has_many :galleries, through: :gallery_images
  44. has_one :category, through: :gallery_images #-> I think
  45. end
  46.  
  47. #app/models/gallery.rb
  48. Class Gallery < ActiveRecord::Base
  49. has_many :gallery_images
  50. has_many :images, through: :gallery_images
  51. end
  52.  
  53. #app/models/gallery_category.rb
  54. Class GalleryImage < ActiveRecord::Base
  55. belongs_to :gallery
  56. belongs_to :image
  57. belongs_to :category
  58. end
  59.  
  60. #app/models/gallery_category.rb
  61. Class GalleryCategory < ActiveRecord::Base
  62. belongs_to :gallery
  63. has_many :gallery_images
  64. end
  65.  
  66. images
  67. id | image_info | created_at | updated_at
  68.  
  69. galleries
  70. id | name | created_at | updated_at
  71.  
  72. gallery_images
  73. image_id | gallery_id | category_id
  74.  
  75. gallery_categories
  76. id | gallery_id | name | created_at | updated_at
  77.  
  78. gallery_images
  79. id | gallery_id | image_id | type | created_at | updated_at
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement