Upload Picture to Rails App
How to upload picture in rails app ?
If you want to upload picture in your rails app, you should make
- Open your
Gemfile
in rails app then add
1
|
|
in terminal write bundle
for install gem.
Which models do you want to upload picture ? For example, you have
books
model, because of this, I write all command according tobook
model.After install
paperclip
gem, open yourterminal
again then write
1
|
|
then
1
|
|
- Open
models/book.rb
add
1 2 3 4 5 6 7 |
|
- Open
books/show.html.haml
add
1
|
|
- Open
books/_form.html.haml
add
1 2 |
|
- Open
controllers/books_controller.rb
, then checkcreate
method if you use
1 2 3 |
|
instead of above, you should write
1 2 3 |
|
Lastly, you should control to add :photo
in your book_params
method.
1 2 3 4 |
|
If you want to learn with details, you can visit this site
That’ s all.