From c299d467086e8405ba9c5786612b7904b2985e71 Mon Sep 17 00:00:00 2001 From: Nico Date: Fri, 8 Feb 2013 01:40:18 +0100 Subject: [PATCH] go to image page --- app/models/portfolio_image.rb | 10 ++++++++++ app/views/portfolios/index.html.haml | 2 +- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/app/models/portfolio_image.rb b/app/models/portfolio_image.rb index 7f97df4..05be7ac 100644 --- a/app/models/portfolio_image.rb +++ b/app/models/portfolio_image.rb @@ -9,6 +9,16 @@ class PortfolioImage < ActiveRecord::Base scope :after, lambda {|time| {:conditions => ["shoot_at > ?", time]}} + def position(portfolio) + portfolio.images.after(self.shoot_at).count+1 + + end + + def page(portfolio) + per_page = portfolio.content_type || 1 + (self.position(portfolio)/(per_page*1.0)).ceil + end + def width self.photo.geometry[:width] end diff --git a/app/views/portfolios/index.html.haml b/app/views/portfolios/index.html.haml index a8eb826..09a0298 100644 --- a/app/views/portfolios/index.html.haml +++ b/app/views/portfolios/index.html.haml @@ -7,7 +7,7 @@ -@index_images.each do |img| - =link_to image_tag(img.photo.square.url), img.portfolios.first.path + =link_to image_tag(img.photo.square.url), portfolio_path(:id => img.portfolios.first.slug, :page => img.page(img.portfolios.first),:position => img.position(img.portfolios.first)) %p{:style => "clear:both;height:2px;"} :javascript function size_index_images(){