ripta-dm-paperclip 2.5.0.2 → 2.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.markdown +118 -0
- data/Rakefile +3 -3
- data/lib/dm-paperclip/attachment.rb +2 -2
- data/lib/dm-paperclip/storage.rb +5 -5
- data/lib/dm-paperclip/validations.rb +5 -5
- data/lib/dm-paperclip.rb +2 -2
- data/test/fixtures/s3.yml +8 -0
- data/test/helper.rb +5 -1
- metadata +12 -70
- data/README.rdoc +0 -116
data/README.markdown
ADDED
@@ -0,0 +1,118 @@
|
|
1
|
+
# DataMapper Paperclip
|
2
|
+
|
3
|
+
**Compatibility note:** dm-paperclip 2.5.0 requires datamapper (dm-core) 1.0, while dm-paperclip 2.5.1 requires dm-core 1.1.
|
4
|
+
|
5
|
+
dm-paperclip is a port of Thoughtbot's Paperclip plugin to work with DataMapper. This plugin is fully compatible with
|
6
|
+
the original ActiveRecord-oriented Paperclip. You could take an existing ActiveRecord database and use it with DataMapper.
|
7
|
+
The module also includes updates validation handling and automatic including of the necessary 'property' fields into
|
8
|
+
your model.
|
9
|
+
|
10
|
+
To use it within your models, you need to ensure the three database fields are included. They are `{name}_file_name`,
|
11
|
+
`{name}_content_type`, and `{name}_file_size`. The first two are strings, the final column (file size) is an integer. So
|
12
|
+
if your user model has an avatar field, then you would add `avatar_file_name`, `avatar_content_type`, and `avatar_file_size`.
|
13
|
+
|
14
|
+
As with the original Paperclip plugin, it allows processing of thumbnails at the time the record is saved though _ImageMagick_.
|
15
|
+
It processes the thumbnails through the command-line applications instead of using _RMagick_.
|
16
|
+
|
17
|
+
See the documentation for the `has_attached_file` method for options.
|
18
|
+
|
19
|
+
## Code
|
20
|
+
|
21
|
+
The code dm-paperclip is available at Github:
|
22
|
+
|
23
|
+
git clone git://github.com/krobertson/dm-paperclip.git
|
24
|
+
|
25
|
+
It is regularly updated to keep in sync with the latest from Thoughtbot.
|
26
|
+
|
27
|
+
Releases are tagged within the repository and versioned the same as the original model. You can also get the latest release
|
28
|
+
packaged as a gem through Rubyforge:
|
29
|
+
|
30
|
+
sudo gem install dm-paperclip
|
31
|
+
|
32
|
+
## Usage
|
33
|
+
|
34
|
+
In your model:
|
35
|
+
|
36
|
+
class User
|
37
|
+
include DataMapper::Resource
|
38
|
+
include Paperclip::Resource
|
39
|
+
property :id, Serial
|
40
|
+
property :username, String
|
41
|
+
has_attached_file :avatar,
|
42
|
+
:styles => { :medium => "300x300>",
|
43
|
+
:thumb => "100x100>" }
|
44
|
+
end
|
45
|
+
|
46
|
+
You will need to add an initializer to configure Paperclip. If on Rails, can add a config/initializers/paperclip.rb, on Merb
|
47
|
+
can use config/init.rb and add it to the Merb::BootLoader.after_app_loads section. Can also use environment configs, rackup
|
48
|
+
file, Rake task, wherever.
|
49
|
+
|
50
|
+
Paperclip.configure do |config|
|
51
|
+
config.root = Rails.root # the application root to anchor relative urls (defaults to Dir.pwd)
|
52
|
+
config.env = Rails.env # server env support, defaults to ENV['RACK_ENV'] or 'development'
|
53
|
+
config.use_dm_validations = true # validate attachment sizes and such, defaults to false
|
54
|
+
config.processors_path = 'lib/pc' # relative path to look for processors, defaults to 'lib/paperclip_processors'
|
55
|
+
end
|
56
|
+
|
57
|
+
Your database will need to add four columns, `avatar_file_name` (varchar), `avatar_content_type` (varchar), and
|
58
|
+
`avatar_file_size` (integer), and `avatar_updated_at` (datetime). You can either add these manually, auto-
|
59
|
+
migrate, or use the following migration:
|
60
|
+
|
61
|
+
migration( 1, :add_user_paperclip_fields ) do
|
62
|
+
up do
|
63
|
+
modify_table :users do
|
64
|
+
add_column :avatar_file_name, "varchar(255)"
|
65
|
+
add_column :avatar_content_type, "varchar(255)"
|
66
|
+
add_column :avatar_file_size, "integer"
|
67
|
+
add_column :avatar_updated_at, "datetime"
|
68
|
+
end
|
69
|
+
end
|
70
|
+
down do
|
71
|
+
modify_table :users do
|
72
|
+
drop_columns :avatar_file_name, :avatar_content_type, :avatar_file_size, :avatar_updated_at
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
In your edit and new views:
|
78
|
+
|
79
|
+
<% form_for @user, { :action => url(:user), :multipart => true } do %>
|
80
|
+
<%= file_field :name => 'avatar' %>
|
81
|
+
<% end %>
|
82
|
+
|
83
|
+
In your controller:
|
84
|
+
|
85
|
+
def create
|
86
|
+
...
|
87
|
+
@user.avatar = params[:avatar]
|
88
|
+
end
|
89
|
+
|
90
|
+
In your show view:
|
91
|
+
|
92
|
+
<%= image_tag @user.avatar.url %>
|
93
|
+
<%= image_tag @user.avatar.url(:medium) %>
|
94
|
+
<%= image_tag @user.avatar.url(:thumb) %>
|
95
|
+
|
96
|
+
The following validations are available:
|
97
|
+
|
98
|
+
validates_attachment_presence :avatar
|
99
|
+
validates_attachment_content_type :avatar, :content_type => "image/png"
|
100
|
+
validates_attachment_size :avatar, :in => 1..10240
|
101
|
+
validates_attachment_thumbnails :avatar
|
102
|
+
|
103
|
+
In order to use validations, you must have loaded the 'dm-validations' gem into your app
|
104
|
+
(available as a part of dm-more). If the gem isn't loaded before DM-Paperclip is loaded,
|
105
|
+
the validation methods will be excluded. You will also need to include DataMapper::Validate
|
106
|
+
into your mode:
|
107
|
+
|
108
|
+
class User
|
109
|
+
include DataMapper::Resource
|
110
|
+
include DataMapper::Validate
|
111
|
+
include Paperclip::Resource
|
112
|
+
property :id, Serial
|
113
|
+
property :username, String
|
114
|
+
has_attached_file :avatar,
|
115
|
+
:styles => { :medium => "300x300>",
|
116
|
+
:thumb => "100x100>" }
|
117
|
+
validates_attachment_size :avatar, :in => 1..5120
|
118
|
+
end
|
data/Rakefile
CHANGED
@@ -34,7 +34,7 @@ Rake::RDocTask.new(:doc) do |rdoc|
|
|
34
34
|
rdoc.rdoc_dir = 'doc'
|
35
35
|
rdoc.title = 'DM-Paperclip'
|
36
36
|
rdoc.options << '--line-numbers' << '--inline-source'
|
37
|
-
rdoc.rdoc_files.include('README.
|
37
|
+
rdoc.rdoc_files.include('README.markdown')
|
38
38
|
rdoc.rdoc_files.include('lib/**/*.rb')
|
39
39
|
end
|
40
40
|
|
@@ -63,7 +63,7 @@ spec = Gem::Specification.new do |s|
|
|
63
63
|
s.homepage = "http://invalidlogic.com/dm-paperclip/"
|
64
64
|
s.platform = Gem::Platform::RUBY
|
65
65
|
s.summary = "File attachments as attributes for DataMapper, based on the original Paperclip by Jon Yurek at Thoughtbot"
|
66
|
-
s.files = FileList["README.
|
66
|
+
s.files = FileList["README.markdown",
|
67
67
|
"LICENSE",
|
68
68
|
"Rakefile",
|
69
69
|
"init.rb",
|
@@ -72,7 +72,7 @@ spec = Gem::Specification.new do |s|
|
|
72
72
|
s.test_files = FileList["test/**/test_*.rb"].to_a
|
73
73
|
s.rubyforge_project = "dm-paperclip"
|
74
74
|
s.has_rdoc = true
|
75
|
-
s.extra_rdoc_files = ["README.
|
75
|
+
s.extra_rdoc_files = ["README.markdown"]
|
76
76
|
s.rdoc_options << '--line-numbers' << '--inline-source'
|
77
77
|
s.requirements << "ImageMagick"
|
78
78
|
s.requirements << "data_mapper"
|
@@ -77,7 +77,7 @@ module Paperclip
|
|
77
77
|
return nil if uploaded_file.nil?
|
78
78
|
|
79
79
|
if uploaded_file.respond_to?(:[])
|
80
|
-
uploaded_file = uploaded_file.to_mash
|
80
|
+
# uploaded_file = uploaded_file.to_mash
|
81
81
|
|
82
82
|
@queued_for_write[:original] = uploaded_file['tempfile']
|
83
83
|
instance_write(:file_name, uploaded_file['filename'].strip.gsub(/[^\w\d\.\-]+/, '_'))
|
@@ -85,7 +85,7 @@ module Paperclip
|
|
85
85
|
instance_write(:file_size, uploaded_file['size'] ? uploaded_file['size'].to_i : uploaded_file['tempfile'].size.to_i)
|
86
86
|
instance_write(:updated_at, Time.now)
|
87
87
|
else
|
88
|
-
@queued_for_write[:original] = uploaded_file.
|
88
|
+
@queued_for_write[:original] = uploaded_file.to_tempfile
|
89
89
|
instance_write(:file_name, uploaded_file.original_filename.strip.gsub(/[^\w\d\.\-]+/, '_'))
|
90
90
|
instance_write(:content_type, uploaded_file.content_type.to_s.strip)
|
91
91
|
instance_write(:file_size, uploaded_file.size.to_i)
|
data/lib/dm-paperclip/storage.rb
CHANGED
@@ -172,15 +172,15 @@ module Paperclip
|
|
172
172
|
end
|
173
173
|
|
174
174
|
def parse_credentials creds
|
175
|
-
creds = find_credentials(creds).
|
175
|
+
creds = find_credentials(creds).to_hash.stringify_keys
|
176
176
|
if defined? Merb && Merb.respond_to?(:env)
|
177
|
-
(creds[Merb.env] || creds).symbolize_keys
|
177
|
+
(creds[Merb.env.to_s] || creds).symbolize_keys
|
178
178
|
elsif defined? RAILS_ENV
|
179
|
-
(creds[RAILS_ENV] || creds).symbolize_keys
|
179
|
+
(creds[RAILS_ENV.to_s] || creds).symbolize_keys
|
180
180
|
elsif defined? Rails && Rails.respond_to(:env)
|
181
|
-
(creds[Rails.env] || creds).symbolize_keys
|
181
|
+
(creds[Rails.env.to_s] || creds).symbolize_keys
|
182
182
|
elsif defined? RACK_ENV
|
183
|
-
(creds[RACK_ENV] || creds).symbolize_keys
|
183
|
+
(creds[RACK_ENV.to_s] || creds).symbolize_keys
|
184
184
|
else
|
185
185
|
creds.symbolize_keys
|
186
186
|
end
|
@@ -51,9 +51,9 @@ module Paperclip
|
|
51
51
|
return true if @options[:in].include? field_value.to_i
|
52
52
|
|
53
53
|
error_message ||= @options[:message] unless @options[:message].nil?
|
54
|
-
error_message ||= "%s must be less than %s bytes".
|
55
|
-
error_message ||= "%s must be greater than %s bytes".
|
56
|
-
error_message ||= "%s must be between %s and %s bytes".
|
54
|
+
error_message ||= sprintf("%s must be less than %s bytes", @field_name.to_s.humanize, @options[:less_than]) unless @options[:less_than].nil?
|
55
|
+
error_message ||= sprintf("%s must be greater than %s bytes", @field_name.to_s.humanize, @options[:greater_than]) unless @options[:greater_than].nil?
|
56
|
+
error_message ||= sprintf("%s must be between %s and %s bytes", @field_name.to_s.humanize, @options[:in].first, @options[:in].last)
|
57
57
|
add_error(target, error_message , @field_name)
|
58
58
|
return false
|
59
59
|
end
|
@@ -68,7 +68,7 @@ module Paperclip
|
|
68
68
|
def call(target)
|
69
69
|
field_value = target.validation_property_value(@field_name)
|
70
70
|
if field_value.nil? || field_value.original_filename.blank?
|
71
|
-
error_message = @options[:message] || "%s must be set".
|
71
|
+
error_message = @options[:message] || sprintf("%s must be set", @field_name.to_s.humanize)
|
72
72
|
add_error(target, error_message , @field_name)
|
73
73
|
return false
|
74
74
|
end
|
@@ -91,7 +91,7 @@ module Paperclip
|
|
91
91
|
content_type = target.validation_property_value(:"#{@field_name}_content_type")
|
92
92
|
unless valid_types.any?{|t| t === content_type }
|
93
93
|
error_message ||= @options[:message] unless @options[:message].nil?
|
94
|
-
error_message ||= "%s's content type of '%s' is not a valid content type".
|
94
|
+
error_message ||= sprintf("%s's content type of '%s' is not a valid content type", @field_name.to_s.humanize, content_type)
|
95
95
|
add_error(target, error_message , @field_name)
|
96
96
|
return false
|
97
97
|
end
|
data/lib/dm-paperclip.rb
CHANGED
@@ -43,7 +43,7 @@ require 'dm-paperclip/attachment'
|
|
43
43
|
# documentation for Paperclip::ClassMethods for more useful information.
|
44
44
|
module Paperclip
|
45
45
|
|
46
|
-
VERSION = "2.5.
|
46
|
+
VERSION = "2.5.1"
|
47
47
|
|
48
48
|
# To configure Paperclip, put this code in an initializer, Rake task, or wherever:
|
49
49
|
#
|
@@ -170,7 +170,7 @@ module Paperclip
|
|
170
170
|
end
|
171
171
|
|
172
172
|
def processor name #:nodoc:
|
173
|
-
name = name.to_s.
|
173
|
+
name = name.to_s.camelize
|
174
174
|
processor = Paperclip.const_get(name)
|
175
175
|
unless processor.ancestors.include?(Paperclip::Processor)
|
176
176
|
raise PaperclipError.new("[paperclip] Processor #{name} was not found")
|
data/test/helper.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ripta-dm-paperclip
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 25
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 2
|
8
8
|
- 5
|
9
|
-
-
|
10
|
-
|
11
|
-
version: 2.5.0.2
|
9
|
+
- 1
|
10
|
+
version: 2.5.1
|
12
11
|
platform: ruby
|
13
12
|
authors:
|
14
13
|
- Ken Robertson
|
@@ -16,69 +15,10 @@ autorequire:
|
|
16
15
|
bindir: bin
|
17
16
|
cert_chain: []
|
18
17
|
|
19
|
-
date: 2011-
|
18
|
+
date: 2011-04-06 00:00:00 -04:00
|
20
19
|
default_executable:
|
21
|
-
dependencies:
|
22
|
-
|
23
|
-
name: dm-core
|
24
|
-
prerelease: false
|
25
|
-
requirement: &id001 !ruby/object:Gem::Requirement
|
26
|
-
none: false
|
27
|
-
requirements:
|
28
|
-
- - ~>
|
29
|
-
- !ruby/object:Gem::Version
|
30
|
-
hash: 23
|
31
|
-
segments:
|
32
|
-
- 1
|
33
|
-
- 0
|
34
|
-
- 0
|
35
|
-
version: 1.0.0
|
36
|
-
type: :runtime
|
37
|
-
version_requirements: *id001
|
38
|
-
- !ruby/object:Gem::Dependency
|
39
|
-
name: shoulda
|
40
|
-
prerelease: false
|
41
|
-
requirement: &id002 !ruby/object:Gem::Requirement
|
42
|
-
none: false
|
43
|
-
requirements:
|
44
|
-
- - ">="
|
45
|
-
- !ruby/object:Gem::Version
|
46
|
-
hash: 3
|
47
|
-
segments:
|
48
|
-
- 0
|
49
|
-
version: "0"
|
50
|
-
type: :development
|
51
|
-
version_requirements: *id002
|
52
|
-
- !ruby/object:Gem::Dependency
|
53
|
-
name: mocha
|
54
|
-
prerelease: false
|
55
|
-
requirement: &id003 !ruby/object:Gem::Requirement
|
56
|
-
none: false
|
57
|
-
requirements:
|
58
|
-
- - "="
|
59
|
-
- !ruby/object:Gem::Version
|
60
|
-
hash: 43
|
61
|
-
segments:
|
62
|
-
- 0
|
63
|
-
- 9
|
64
|
-
- 8
|
65
|
-
version: 0.9.8
|
66
|
-
type: :development
|
67
|
-
version_requirements: *id003
|
68
|
-
- !ruby/object:Gem::Dependency
|
69
|
-
name: aws-s3
|
70
|
-
prerelease: false
|
71
|
-
requirement: &id004 !ruby/object:Gem::Requirement
|
72
|
-
none: false
|
73
|
-
requirements:
|
74
|
-
- - ">="
|
75
|
-
- !ruby/object:Gem::Version
|
76
|
-
hash: 3
|
77
|
-
segments:
|
78
|
-
- 0
|
79
|
-
version: "0"
|
80
|
-
type: :development
|
81
|
-
version_requirements: *id004
|
20
|
+
dependencies: []
|
21
|
+
|
82
22
|
description:
|
83
23
|
email: ken@invalidlogic.com
|
84
24
|
executables: []
|
@@ -86,9 +26,9 @@ executables: []
|
|
86
26
|
extensions: []
|
87
27
|
|
88
28
|
extra_rdoc_files:
|
89
|
-
- README.
|
29
|
+
- README.markdown
|
90
30
|
files:
|
91
|
-
- README.
|
31
|
+
- README.markdown
|
92
32
|
- LICENSE
|
93
33
|
- Rakefile
|
94
34
|
- init.rb
|
@@ -109,6 +49,7 @@ files:
|
|
109
49
|
- test/fixtures/50x50.png
|
110
50
|
- test/fixtures/5k.png
|
111
51
|
- test/fixtures/bad.png
|
52
|
+
- test/fixtures/s3.yml
|
112
53
|
- test/fixtures/text.txt
|
113
54
|
- test/geometry_test.rb
|
114
55
|
- test/helper.rb
|
@@ -118,7 +59,7 @@ files:
|
|
118
59
|
- test/storage_test.rb
|
119
60
|
- test/thumbnail_test.rb
|
120
61
|
has_rdoc: true
|
121
|
-
homepage: http://
|
62
|
+
homepage: http://invalidlogic.com/dm-paperclip/
|
122
63
|
licenses: []
|
123
64
|
|
124
65
|
post_install_message:
|
@@ -147,8 +88,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
147
88
|
version: "0"
|
148
89
|
requirements:
|
149
90
|
- ImageMagick
|
91
|
+
- data_mapper
|
150
92
|
rubyforge_project: dm-paperclip
|
151
|
-
rubygems_version: 1.
|
93
|
+
rubygems_version: 1.6.2
|
152
94
|
signing_key:
|
153
95
|
specification_version: 3
|
154
96
|
summary: File attachments as attributes for DataMapper, based on the original Paperclip by Jon Yurek at Thoughtbot
|
data/README.rdoc
DELETED
@@ -1,116 +0,0 @@
|
|
1
|
-
=DataMapper Paperclip
|
2
|
-
|
3
|
-
DM-Paperclip is a port of Thoughtbot's Paperclip plugin to work with DataMapper. This plugin is fully compatible with
|
4
|
-
the original ActiveRecord-oriented Paperclip. You could take an existing ActiveRecord database and use it with DataMapper.
|
5
|
-
The module also includes updates validation handling and automatic including of the necessary 'property' fields into
|
6
|
-
your model.
|
7
|
-
|
8
|
-
To use it within your models, you need to ensure the three database fields are included. They are {name}_file_name,
|
9
|
-
{name}_content_type, and {name}_file_size. The first two are strings, the final _file_size column is an integer. So
|
10
|
-
if your user model has an avatar field, then you would add avatar_file_name, avatar_content_type, and avatar_file_size.
|
11
|
-
|
12
|
-
As with the original Paperclip plugin, it allows processing of thumbnails at the time the record is saved though ImageMagick.
|
13
|
-
It processes the thumbnails through the command-line applications instead of using RMagick.
|
14
|
-
|
15
|
-
See the documentation for the +has_attached_file+ method for options.
|
16
|
-
|
17
|
-
==Code
|
18
|
-
|
19
|
-
The code DM-Paperclip is available at Github:
|
20
|
-
|
21
|
-
git clone git://github.com/krobertson/dm-paperclip.git
|
22
|
-
|
23
|
-
It is regularly updated to keep in sync with the latest from Thoughtbot.
|
24
|
-
|
25
|
-
Releases are tagged within the repository and versioned the same as the original model. You can also get the latest release
|
26
|
-
packaged as a gem through Rubyforge:
|
27
|
-
|
28
|
-
sudo gem install dm-paperclip
|
29
|
-
|
30
|
-
==Usage
|
31
|
-
|
32
|
-
In your model:
|
33
|
-
|
34
|
-
class User
|
35
|
-
include DataMapper::Resource
|
36
|
-
include Paperclip::Resource
|
37
|
-
property :id, Serial
|
38
|
-
property :username, String
|
39
|
-
has_attached_file :avatar,
|
40
|
-
:styles => { :medium => "300x300>",
|
41
|
-
:thumb => "100x100>" }
|
42
|
-
end
|
43
|
-
|
44
|
-
You will need to add an initializer to configure Paperclip. If on Rails, can add a config/initializers/paperclip.rb, on Merb
|
45
|
-
can use config/init.rb and add it to the Merb::BootLoader.after_app_loads section. Can also use environment configs, rackup
|
46
|
-
file, Rake task, wherever.
|
47
|
-
|
48
|
-
Paperclip.configure do |config|
|
49
|
-
config.root = Rails.root # the application root to anchor relative urls (defaults to Dir.pwd)
|
50
|
-
config.env = Rails.env # server env support, defaults to ENV['RACK_ENV'] or 'development'
|
51
|
-
config.use_dm_validations = true # validate attachment sizes and such, defaults to false
|
52
|
-
config.processors_path = 'lib/pc' # relative path to look for processors, defaults to 'lib/paperclip_processors'
|
53
|
-
end
|
54
|
-
|
55
|
-
Your database will need to add four columns, avatar_file_name (varchar), avatar_content_type (varchar), and
|
56
|
-
avatar_file_size (integer), and avatar_updated_at (datetime). You can either add these manually, auto-
|
57
|
-
migrate, or use the following migration:
|
58
|
-
|
59
|
-
migration( 1, :add_user_paperclip_fields ) do
|
60
|
-
up do
|
61
|
-
modify_table :users do
|
62
|
-
add_column :avatar_file_name, "varchar(255)"
|
63
|
-
add_column :avatar_content_type, "varchar(255)"
|
64
|
-
add_column :avatar_file_size, "integer"
|
65
|
-
add_column :avatar_updated_at, "datetime"
|
66
|
-
end
|
67
|
-
end
|
68
|
-
down do
|
69
|
-
modify_table :users do
|
70
|
-
drop_columns :avatar_file_name, :avatar_content_type, :avatar_file_size, :avatar_updated_at
|
71
|
-
end
|
72
|
-
end
|
73
|
-
end
|
74
|
-
|
75
|
-
In your edit and new views:
|
76
|
-
|
77
|
-
<% form_for @user, { :action => url(:user), :multipart => true } do %>
|
78
|
-
<%= file_field :name => 'avatar' %>
|
79
|
-
<% end %>
|
80
|
-
|
81
|
-
In your controller:
|
82
|
-
|
83
|
-
def create
|
84
|
-
...
|
85
|
-
@user.avatar = params[:avatar]
|
86
|
-
end
|
87
|
-
|
88
|
-
In your show view:
|
89
|
-
|
90
|
-
<%= image_tag @user.avatar.url %>
|
91
|
-
<%= image_tag @user.avatar.url(:medium) %>
|
92
|
-
<%= image_tag @user.avatar.url(:thumb) %>
|
93
|
-
|
94
|
-
The following validations are available:
|
95
|
-
|
96
|
-
validates_attachment_presence :avatar
|
97
|
-
validates_attachment_content_type :avatar, :content_type => "image/png"
|
98
|
-
validates_attachment_size :avatar, :in => 1..10240
|
99
|
-
validates_attachment_thumbnails :avatar
|
100
|
-
|
101
|
-
In order to use validations, you must have loaded the 'dm-validations' gem into your app
|
102
|
-
(available as a part of dm-more). If the gem isn't loaded before DM-Paperclip is loaded,
|
103
|
-
the validation methods will be excluded. You will also need to include DataMapper::Validate
|
104
|
-
into your mode:
|
105
|
-
|
106
|
-
class User
|
107
|
-
include DataMapper::Resource
|
108
|
-
include DataMapper::Validate
|
109
|
-
include Paperclip::Resource
|
110
|
-
property :id, Serial
|
111
|
-
property :username, String
|
112
|
-
has_attached_file :avatar,
|
113
|
-
:styles => { :medium => "300x300>",
|
114
|
-
:thumb => "100x100>" }
|
115
|
-
validates_attachment_size :avatar, :in => 1..5120
|
116
|
-
end
|