Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
P
paperclip
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
ikcrm_common
paperclip
Commits
c334c989
Commit
c334c989
authored
Jun 07, 2010
by
Jon Yurek
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
All generators working with Rails 2 and 3. Tested in app for Rails 2 and 3.
parent
f2ef8c40
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
14 additions
and
19 deletions
+14
-19
lib/generators/paperclip/paperclip_generator.rb
+3
-9
lib/generators/paperclip/templates/paperclip_migration.rb.erb
+8
-8
lib/paperclip.rb
+1
-1
lib/paperclip/railtie.rb
+1
-1
rails/init.rb
+1
-0
No files found.
lib/generators/paperclip/paperclip_generator.rb
View file @
c334c989
class
PaperclipGenerator
<
Rails
::
Generators
::
Base
require
'rails/generators/active_record'
include
Rails
::
Generators
::
Migration
class
PaperclipGenerator
<
ActiveRecord
::
Generators
::
Base
desc
"Create a migration to add paperclip-specific fields to your model."
desc
"Create a migration to add paperclip-specific fields to your model."
argument
:attachment_class
,
:required
=>
true
,
:type
=>
:string
,
:desc
=>
"The class to migrate."
,
:banner
=>
"ClassName"
argument
:attachment_names
,
:required
=>
true
,
:type
=>
:array
,
:desc
=>
"The names of the attachment(s) to add."
,
argument
:attachment_names
,
:required
=>
true
,
:type
=>
:array
,
:desc
=>
"The names of the attachment(s) to add."
,
:banner
=>
"attachment_one attachment_two attachment_three ..."
:banner
=>
"attachment_one attachment_two attachment_three ..."
...
@@ -19,7 +17,7 @@ class PaperclipGenerator < Rails::Generators::Base
...
@@ -19,7 +17,7 @@ class PaperclipGenerator < Rails::Generators::Base
protected
protected
def
migration_name
def
migration_name
"add_attachment_
#{
attachment_names
.
join
(
"_"
)
}
_to_
#{
attachment_class
.
underscore
}
"
"add_attachment_
#{
attachment_names
.
join
(
"_"
)
}
_to_
#{
name
.
underscore
}
"
end
end
def
migration_file_name
def
migration_file_name
...
@@ -30,8 +28,4 @@ class PaperclipGenerator < Rails::Generators::Base
...
@@ -30,8 +28,4 @@ class PaperclipGenerator < Rails::Generators::Base
migration_name
.
camelize
migration_name
.
camelize
end
end
def
self
.
next_migration_number
(
dirname
)
#:nodoc:
Time
.
now
.
strftime
(
"%Y%m%d%H%M%S"
)
end
end
end
lib/generators/paperclip/templates/paperclip_migration.rb.erb
View file @
c334c989
class
<%=
migration_class_name
%>
<
ActiveRecord::Migration
class
<%=
migration_class_name
%>
<
ActiveRecord::Migration
def
self
.
up
def
self
.
up
<%
attachment_names
.
each
do
|
attachment
|
-%>
<%
attachment_names
.
each
do
|
attachment
|
-%>
add_column
:
<%=
attachment_class
.
underscore
.
camelize
.
tableize
%>
,
:
<%=
attachment
%>
_file_name
,
:string
add_column
:
<%=
name
.
underscore
.
camelize
.
tableize
%>
,
:
<%=
attachment
%>
_file_name
,
:string
add_column
:
<%=
attachment_class
.
underscore
.
camelize
.
tableize
%>
,
:
<%=
attachment
%>
_content_type
,
:string
add_column
:
<%=
name
.
underscore
.
camelize
.
tableize
%>
,
:
<%=
attachment
%>
_content_type
,
:string
add_column
:
<%=
attachment_class
.
underscore
.
camelize
.
tableize
%>
,
:
<%=
attachment
%>
_file_size
,
:integer
add_column
:
<%=
name
.
underscore
.
camelize
.
tableize
%>
,
:
<%=
attachment
%>
_file_size
,
:integer
add_column
:
<%=
attachment_class
.
underscore
.
camelize
.
tableize
%>
,
:
<%=
attachment
%>
_updated_at
,
:datetime
add_column
:
<%=
name
.
underscore
.
camelize
.
tableize
%>
,
:
<%=
attachment
%>
_updated_at
,
:datetime
<%
end
-%>
<%
end
-%>
end
end
def
self
.
down
def
self
.
down
<%
attachment_names
.
each
do
|
attachment
|
-%>
<%
attachment_names
.
each
do
|
attachment
|
-%>
remove_column
:
<%=
attachment_class
.
underscore
.
camelize
.
tableize
%>
,
:
<%=
attachment
%>
_file_name
remove_column
:
<%=
name
.
underscore
.
camelize
.
tableize
%>
,
:
<%=
attachment
%>
_file_name
remove_column
:
<%=
attachment_class
.
underscore
.
camelize
.
tableize
%>
,
:
<%=
attachment
%>
_content_type
remove_column
:
<%=
name
.
underscore
.
camelize
.
tableize
%>
,
:
<%=
attachment
%>
_content_type
remove_column
:
<%=
attachment_class
.
underscore
.
camelize
.
tableize
%>
,
:
<%=
attachment
%>
_file_size
remove_column
:
<%=
name
.
underscore
.
camelize
.
tableize
%>
,
:
<%=
attachment
%>
_file_size
remove_column
:
<%=
attachment_class
.
underscore
.
camelize
.
tableize
%>
,
:
<%=
attachment
%>
_updated_at
remove_column
:
<%=
name
.
underscore
.
camelize
.
tableize
%>
,
:
<%=
attachment
%>
_updated_at
<%
end
-%>
<%
end
-%>
end
end
end
end
lib/paperclip.rb
View file @
c334c989
...
@@ -337,7 +337,7 @@ module Paperclip
...
@@ -337,7 +337,7 @@ module Paperclip
@_paperclip_attachments
||=
{}
@_paperclip_attachments
||=
{}
@_paperclip_attachments
[
name
]
||=
Attachment
.
new
(
name
,
self
,
self
.
class
.
attachment_definitions
[
name
])
@_paperclip_attachments
[
name
]
||=
Attachment
.
new
(
name
,
self
,
self
.
class
.
attachment_definitions
[
name
])
end
end
def
each_attachment
def
each_attachment
self
.
class
.
attachment_definitions
.
each
do
|
name
,
definition
|
self
.
class
.
attachment_definitions
.
each
do
|
name
,
definition
|
yield
(
name
,
attachment_for
(
name
))
yield
(
name
,
attachment_for
(
name
))
...
...
lib/paperclip/railtie.rb
View file @
c334c989
...
@@ -4,7 +4,7 @@ module Paperclip
...
@@ -4,7 +4,7 @@ module Paperclip
if
defined?
Rails
::
Railtie
if
defined?
Rails
::
Railtie
require
'rails'
require
'rails'
class
Railtie
<
Rails
::
Railtie
class
Railtie
<
Rails
::
Railtie
config
.
after_initialize
do
initializer
"paperclip.insert_into_active_record"
do
Paperclip
::
Railtie
.
insert
Paperclip
::
Railtie
.
insert
end
end
rake_tasks
do
rake_tasks
do
...
...
rails/init.rb
View file @
c334c989
puts
"THIS IS THE RAILS/INIT.RB FILE"
require
'paperclip/railtie'
require
'paperclip/railtie'
Paperclip
::
Railtie
.
insert
Paperclip
::
Railtie
.
insert
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment