Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Gallery < ActiveRecord::Base
- belongs_to :category
- has_many :gallery_images, dependent: :destroy
- accepts_nested_attributes_for :gallery_images, allow_destroy: true
- end
- class GalleryImage < ActiveRecord::Base
- belongs_to :gallery
- belongs_to :gallery_category
- end
- class GalleryCategory < ActiveRecord::Base
- has_many :gallery_images
- end
- <% for image in @gallery.gallery_images %>
- <li><%= image_tag(image.photo.url(:gallery_flexslider)) %>
- <p class="flex-caption"></p>
- </li>
- <% end %>
- <p class="flex-caption"></p>
- <% @gallery.gallery_images.each do |image| %>
- <li><%= image_tag(image.photo.url(:gallery_flexslider)) %>
- <p class="flex-caption"><%= image.gallery_category.name %></p>
- </li>
- <% end %>
- <% @gallery.gallery_images.each do |image| %>
- <li>
- <%= image_tag(image.photo.url(:gallery_flexslider)) %>
- <% image.gallery_categories.each do |c| %>
- <p class="flex-caption"><%= c.name %></p>
- <% end %>
- </li>
- <% end %>
- #app/models/image.rb
- Class Image < ActiveRecord::Base
- has_many :gallery_images
- has_many :galleries, through: :gallery_images
- has_one :category, through: :gallery_images #-> I think
- end
- #app/models/gallery.rb
- Class Gallery < ActiveRecord::Base
- has_many :gallery_images
- has_many :images, through: :gallery_images
- end
- #app/models/gallery_category.rb
- Class GalleryImage < ActiveRecord::Base
- belongs_to :gallery
- belongs_to :image
- belongs_to :category
- end
- #app/models/gallery_category.rb
- Class GalleryCategory < ActiveRecord::Base
- belongs_to :gallery
- has_many :gallery_images
- end
- images
- id | image_info | created_at | updated_at
- galleries
- id | name | created_at | updated_at
- gallery_images
- image_id | gallery_id | category_id
- gallery_categories
- id | gallery_id | name | created_at | updated_at
- gallery_images
- id | gallery_id | image_id | type | created_at | updated_at
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement