Skip to content

Commit

Permalink
implemented simple sorting behaviour for attachments in model layer
Browse files Browse the repository at this point in the history
- position column, fill existing positions from creation order
- depend on acts_as_list gem
  • Loading branch information
gerrit committed Mar 20, 2011
1 parent f132744 commit 197c5ee
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 2 deletions.
4 changes: 4 additions & 0 deletions app/models/attachment.rb
@@ -1,7 +1,11 @@
require 'acts_as_list'

class Attachment < ActiveRecord::Base
belongs_to :asset, :autosave => true
belongs_to :page

acts_as_list :scope => :page_id

def uploads=(new_uploads)
(asset || build_asset).uploads=new_uploads
end
Expand Down
2 changes: 1 addition & 1 deletion assets_extension.rb
Expand Up @@ -33,7 +33,7 @@ def activate
ApplicationController.helper(:assets)
Page.class_eval do
include AssetTags
has_many :attachments, :include => :asset
has_many :attachments, :include => :asset, :order => :position
end
end
end
14 changes: 14 additions & 0 deletions db/migrate/20110320152044_add_position_to_attachments.rb
@@ -0,0 +1,14 @@
class AddPositionToAttachments < ActiveRecord::Migration
def self.up
add_column :attachments, :position, :integer
Page.all(:include => :attachments).each do |page|
page.attachments.each_with_index do |attachment, index|
attachment.update_attributes :position => index+1
end
end
end

def self.down
remove_column :attachments, :position
end
end
2 changes: 1 addition & 1 deletion lib/radiant-assets-extension/version.rb
@@ -1,3 +1,3 @@
module RadiantAssetsExtension
VERSION = '0.0.6'
VERSION = '0.0.7'
end
1 change: 1 addition & 0 deletions radiant-assets-extension.gemspec
Expand Up @@ -14,6 +14,7 @@ Gem::Specification.new do |s|

s.add_dependency 'dragonfly', '~>0.8.2'
s.add_dependency 'aws-s3', '~>0.6.2'
s.add_dependency 'acts_as_list', '~>0.1.2'

s.files = `git ls-files`.split("\n")
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
Expand Down

0 comments on commit 197c5ee

Please sign in to comment.