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
efdf952e
Commit
efdf952e
authored
Nov 08, 2013
by
Jon Yurek
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Clarify Rails 3/4 things in the README
parent
8e6c19a9
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
26 additions
and
8 deletions
+26
-8
README.md
+26
-8
No files found.
README.md
View file @
efdf952e
...
...
@@ -96,7 +96,9 @@ end
Quick Start
-----------
In your model:
### Models
**Rails 3**
```
ruby
class
User
<
ActiveRecord
::
Base
...
...
@@ -104,9 +106,16 @@ class User < ActiveRecord::Base
has_attached_file
:avatar
,
:styles
=>
{
:medium
=>
"300x300>"
,
:thumb
=>
"100x100>"
},
:default_url
=>
"/images/:style/missing.png"
end
```
(Note: if you are using Rails 4, leave attr_accessible out to accommodate
[
strong parameters
](
https://github.com/rails/strong_parameters
)
. Instead add the parameters in the controller (see below).)
In your migrations:
**Rails 4**
```
ruby
class
User
<
ActiveRecord
::
Base
has_attached_file
:avatar
,
:styles
=>
{
:medium
=>
"300x300>"
,
:thumb
=>
"100x100>"
},
:default_url
=>
"/images/:style/missing.png"
end
```
### Migrations
```
ruby
class
AddAvatarColumnsToUsers
<
ActiveRecord
::
Migration
...
...
@@ -122,7 +131,7 @@ end
(Or you can use migration generator:
`rails generate paperclip user avatar`
)
In your edit and new views:
### Edit and New Views
```
erb
<%=
form_for
@user
,
:url
=>
users_path
,
:html
=>
{
:multipart
=>
true
}
do
|
form
|
%>
...
...
@@ -130,16 +139,23 @@ In your edit and new views:
<%
end
%>
```
In your controller:
### Controller
**Rails 3**
```
ruby
def
create
@user
=
User
.
create
(
params
[
:user
]
)
end
```
If you are using Rails 4, add this to your controller as well:
**Rails 4**
```
ruby
def
create
@user
=
User
.
create
(
user_params
)
end
private
# Use strong_parameters for attribute whitelisting
...
...
@@ -150,7 +166,7 @@ def user_params
end
```
In your show view:
### Show View
```
erb
<%=
image_tag
@user
.
avatar
.
url
%>
...
...
@@ -158,7 +174,9 @@ In your show view:
<%=
image_tag
@user
.
avatar
.
url
(
:thumb
)
%>
```
To detach a file, simply set the attribute to
`nil`
:
### Deleting an Attachment
Set the attribute to
`nil`
and save.
```
ruby
@user
.
avatar
=
nil
...
...
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