Skip to content

Commit

Permalink
Gallery now is unique for every page
Browse files Browse the repository at this point in the history
  • Loading branch information
html committed Mar 2, 2010
1 parent e94b8dc commit 0cb5c40
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 14 deletions.
13 changes: 7 additions & 6 deletions app/controllers/index_controller.rb
Expand Up @@ -40,15 +40,16 @@ def load_additional_data
@answers = []
end

if @category.show_gallery
@images = Image.random_three
else
@images = []
end

@pages =@category.pages
if @pages.size == 1
@page = @pages.first
end


if @category.show_gallery && @page
@images = Image.random_three @page
else
@images = []
end
end
end
10 changes: 8 additions & 2 deletions app/models/image.rb
@@ -1,9 +1,15 @@
class Image < ActiveRecord::Base
belongs_to :page
validates_presence_of :page
validates_attachment_presence :image

has_attached_file :image, :styles => {
:thumbnail => ["310x180#", :jpg]
}

def self.random_three
all(:order => 'RANDOM()', :limit => 3)
def self.random_three(page)
all(:order => 'RANDOM()', :limit => 3, :conditions => {
:page_id => page.id
})
end
end
5 changes: 5 additions & 0 deletions app/models/page.rb
@@ -1,4 +1,9 @@
class Page < ActiveRecord::Base
has_many :images
belongs_to :category
has_attached_file :image, :styles => { :original => "145x110#" }

def typus_name
title
end
end
7 changes: 2 additions & 5 deletions config/locales/ru.yml
Expand Up @@ -19,11 +19,6 @@ ru:
show_answers: Показывать блок "А знаете ли Вы ?"
show_gallery: Показывать галерею
content: Описание категории. Если есть показывается в левой части страницы для всех страниц категории
album:
title: Заголовок
photo:
title: Заголовок
photo: Фото
typus_user:
first_name: Имя
password: Пароль
Expand All @@ -33,6 +28,8 @@ ru:
password_confirmation: Повторить пароль
language: Язык
status: Статус
image:
page: Страница
hello: Hello
New: Новая
Show: Показать
Expand Down
3 changes: 2 additions & 1 deletion config/typus/app.yml
Expand Up @@ -16,6 +16,7 @@ Page:
fields: content
application: Страницы
description: Все страницы сайта. Содержатся в категориях. Если добавляете в одну категорию несколько страниц не забудьте добавить списочные картинки к каждой странице
relationships: images
Answer:
fields:
list: title
Expand All @@ -28,6 +29,6 @@ Answer:
Image:
fields:
list: image_file_name
form: image_file_name
form: page, image_file_name
application: Галерея
description: Галерея сайта (блок из трех случайных картинок, можно подключать для любой категории)
6 changes: 6 additions & 0 deletions public/stylesheets/style.css
Expand Up @@ -275,3 +275,9 @@ img.right {
a.search{
color: #b30f4b;
}

.certs img {
display:inline;
float:none;
margin:0;
}

0 comments on commit 0cb5c40

Please sign in to comment.