#### What Will I Learn? - You will learn how to add paperclip gem in ruby on rails - You will learn how to upload images using paperclip gem in ruby on rails #### Requirements - OS: Ubuntu/Mac OS - A text editor like sublime - Basic understanding about Ruby on Rails - And for better understanding must refer my previous tutorials (link added to the curriculum) #### Difficulty - Intermediate #### Tutorial Contents Hello and welcome to the next part of the tutorial. In this tutorial, we will learn how to upload images in ruby on rails project. So let's start our tutorial, - Open the terminal and go to your project path that was build in our previous tutroials. If you haven't go through the previous tutroials, please refer those also. - And now start rails server by entring the following command: ``` language rails s ``` - Now open the project in the text editor like sublime text editor. - Now go to the Gemfile and add the following gem and then saved it. ``` language gem "paperclip" ``` - Next go to the terminal and stop the server then run the following command and also start the server again ``` language bundle ``` ###### Bundle command will install the paerclip gem into your project - Once we successfully install the gem, the next step to add code so that our project will accept the images. - You alredy know that we have built a simpe application till now. We have <b> users </b> table in which all the user details are stored but we haven't store the profile picture. - So for that we have to add image column to the <b> users </b> table. - Go to the terminal and stop the server and run the following command: ``` language rails g migration add_image_to_users ``` - The above command will generate a migaration names <b> timestamp_add_image_to_users </b> under the db folder of the proejct. Now go to this migration file and add following code: ``` language class AddImageToUsers < ActiveRecord::Migration def change add_attachment :users, :avatar end end ``` ###### avatar is the name for the column - You can also check if field are added into db or not but opening the users table in the mysql workbench as shown as below  - Now open the registration form for the user and add the following code within the form: ``` language <div class="field"> <%= f.label :avatar%><br /> <%= f.file_field :avatar%> </div> ``` - Or you can see in the below image  - Paste that code in the form and refresh the form. Now you will see the add avatar option as shown in the below image  - Next step is to save this avatar into the database, for that we have to permit the params in the users controller. Go to <b> users > registration_controller </b> and add permit params in the <b> configure_sign_up_params </b> method  - And also we have to tell the user model is to handle the avatar for that add the following code to the user model ``` language has_attached_file :avatar validates_attachment_content_type :avatar ``` Now refresh the form and try to add the user image by clicking the choose file option. Now our app will accept the images. #### Curriculum - Reference of this tutorials for new users to follow up the project, because i am adding paperclip on the same project we created in below tutorials. - https://utopian.io/utopian-io/@amn/how-to-authenticate-user-in-rails-using-devise-part1 - https://utopian.io/utopian-io/@amn/how-to-authenticate-user-in-rails-using-devise-part2 <br /><hr/><em>Posted on <a href="https://utopian.io/utopian-io/@amn/how-to-upload-images-in-ruby-on-rails-using-paperclip">Utopian.io - Rewarding Open Source Contributors</a></em><hr/>
author | amn | ||||||
---|---|---|---|---|---|---|---|
permlink | how-to-upload-images-in-ruby-on-rails-using-paperclip | ||||||
category | utopian-io | ||||||
json_metadata | "{"community":"utopian","app":"utopian/1.0.0","format":"markdown","repository":{"id":8393,"name":"paperclip","full_name":"thoughtbot/paperclip","html_url":"https://github.com/thoughtbot/paperclip","fork":false,"owner":{"login":"thoughtbot"}},"pullRequests":[],"platform":"github","type":"tutorials","tags":["utopian-io","steemstem","utopian-io","rails","tutorials"],"users":["amn"],"moderator":{"account":"deathwing","time":"2018-04-11T11:12:12.531Z","pending":false,"reviewed":true,"flagged":false},"questions":null,"score":null,"total_influence":null,"staff_pick":null,"config":{"questions":[{"question":"Does the tutorial address a minimum of 3 substantial concepts and no more than 5?","question_id":"tut-1","answers":[{"answer":"3-5 substantial concepts covered in the tutorial.","answer_id":1,"value":10},{"answer":"Less than 3 or more than 5 substantial concepts covered in the tutorial.","answer_id":2,"value":5},{"answer":"No substantial or recognisable concepts.","answer_id":3,"value":0}]},{"question":"Concepts covered in the tutorial are indicated in the post text with a short description of each concept and when appropriate, images?","question_id":"tut-2","answers":[{"answer":"Thorough text and images for concepts covered.","answer_id":1,"value":10},{"answer":"Minimal text and images.","answer_id":2,"value":5},{"answer":"No or very little text and images.","answer_id":3,"value":0}]},{"question":"Does the contributor provide supplementary resources, such as code and sample files in the contribution post or a GitHub repository?","question_id":"tut-3","answers":[{"answer":"Yes","answer_id":1,"value":10},{"answer":"No","answer_id":2,"value":0}]},{"question":"Is the tutorial part of a series?","question_id":"tut-4","answers":[{"answer":"Yes.","answer_id":1,"value":10},{"answer":"Yes, but first entry in the series.","answer_id":2,"value":5},{"answer":"No.","answer_id":3,"value":0}]},{"question":"Is there an outline for the tutorial content at the beginning of the post?","question_id":"tut-5","answers":[{"answer":"Yes.","answer_id":1,"value":10},{"answer":"Yes, but not detailed enough or does not cover all sections.","answer_id":2,"value":5},{"answer":"No.","answer_id":3,"value":0}]},{"question":"Does the writing style meet the Utopian standard considering formalness, informativeness and clarity of the content?","question_id":"c-1","answers":[{"answer":"It is formal, informative and well written with clear content.","answer_id":1,"value":10},{"answer":"It is informative with clear content but not formal enough.","answer_id":2,"value":5},{"answer":"The contribution could be more informative or contains unrelated information, formality and clarity of the content are good enough.","answer_id":3,"value":4},{"answer":"Not all sections were clear enough but overall holds value for the project.","answer_id":4,"value":2},{"answer":"Not at all.","answer_id":5,"value":0}]},{"question":"Was the provided category template for the editor followed?","question_id":"c-2","answers":[{"answer":"All points of the template were included with additional points as well.","answer_id":1,"value":5},{"answer":"The template was followed without additions.","answer_id":2,"value":4},{"answer":"The template was edited but the points were covered in different way.","answer_id":3,"value":3},{"answer":"Not all points of the template were covered in the contribution but the structure is clear enough.","answer_id":4,"value":3},{"answer":"The template was not followed but the structure is clear enough.","answer_id":5,"value":2},{"answer":"The contents are not clearly structured at all.","answer_id":6,"value":0}]},{"question":"Did the contributor tag other users?","question_id":"c-3","answers":[{"answer":"No other users were tagged by the contributor.","answer_id":1,"value":5},{"answer":"Used tags are reasonable and all tagged people are connected to the project and/or the contribution.","answer_id":2,"value":5},{"answer":"The contribution contains mentions of other users that are not directly related to the contribution but related in other ways.","answer_id":3,"value":2},{"answer":"The contributor misuses tagging of other users.","answer_id":4,"value":0}]},{"question":"Did the contributor ask for upvotes, resteems, follows or witness vote?","question_id":"c-4","answers":[{"answer":"No","answer_id":1,"value":5},{"answer":"Yes, but not in a way that disturbs readability. ","answer_id":2,"value":5},{"answer":"Yes.","answer_id":3,"value":0}]},{"question":"Was a graphical content like images, charts, videos or screenshots included?","question_id":"c-5","answers":[{"answer":"Yes, the graphical content is included and adds more value to the contribution.","answer_id":1,"value":5},{"answer":"No but the contribution works well without graphical content well.","answer_id":2,"value":4},{"answer":"Yes, but most of the graphical content’s purpose is just for presentational matters.","answer_id":3,"value":3},{"answer":"No relevant or useful graphical content is included in the contribution.","answer_id":4,"value":0}]},{"question":"How would you rate the overall added value?","question_id":"c-6","answers":[{"answer":"Extraordinary value to both the project and the open source community overall.","answer_id":1,"value":20},{"answer":"Significant value to the project or open source community.","answer_id":2,"value":15},{"answer":"Some value to the project or open source community.","answer_id":3,"value":10},{"answer":"Little value to the project or open source community.","answer_id":4,"value":5},{"answer":"No obvious value to project or open source community.","answer_id":5,"value":0}]}]}}" | ||||||
created | 2018-04-09 10:57:48 | ||||||
last_update | 2018-04-11 11:12:15 | ||||||
depth | 0 | ||||||
children | 2 | ||||||
last_payout | 2018-04-16 10:57:48 | ||||||
cashout_time | 1969-12-31 23:59:59 | ||||||
total_payout_value | 40.030 HBD | ||||||
curator_payout_value | 17.669 HBD | ||||||
pending_payout_value | 0.000 HBD | ||||||
promoted | 0.000 HBD | ||||||
body_length | 3,990 | ||||||
author_reputation | 1,578,841,540,124 | ||||||
root_title | "How to upload images in ruby on rails using paperclip" | ||||||
beneficiaries |
| ||||||
max_accepted_payout | 1,000,000.000 HBD | ||||||
percent_hbd | 10,000 | ||||||
post_id | 49,115,819 | ||||||
net_rshares | 15,546,905,535,546 | ||||||
author_curate_reward | "" |
voter | weight | wgt% | rshares | pct | time |
---|---|---|---|---|---|
lafona-miner | 0 | 140,325,200,983 | 5% | ||
bue | 0 | 41,963,158,792 | 100% | ||
justtryme90 | 0 | 114,406,855,342 | 5% | ||
lemouth | 0 | 17,113,745,221 | 3.5% | ||
rjbauer85 | 0 | 309,080,845 | 5% | ||
anarchyhasnogods | 0 | 8,426,224,255 | 2.5% | ||
lamouthe | 0 | 1,325,130,167 | 5% | ||
steemstem | 0 | 138,922,058,891 | 5% | ||
foundation | 0 | 486,292,816 | 5% | ||
the-devil | 0 | 650,148,946 | 5% | ||
thevenusproject | 0 | 2,774,023,084 | 5% | ||
borislavzlatanov | 0 | 428,716,917 | 5% | ||
jamhuery | 0 | 681,518,186 | 5% | ||
followbtcnews | 0 | 31,126,935,274 | 5% | ||
samminator | 0 | 1,886,167,140 | 5% | ||
minnowsupport | 0 | 24,780,782,353 | 0.5% | ||
dber | 0 | 1,106,207,032 | 5% | ||
kerriknox | 0 | 13,468,391,744 | 5% | ||
alexander.alexis | 0 | 446,369,818 | 1.5% | ||
ertwro | 0 | 2,064,467,280 | 5% | ||
juanjdiaz89 | 0 | 208,315,152 | 5% | ||
nitesh9 | 0 | 1,249,755,468 | 5% | ||
himal | 0 | 385,451,605 | 5% | ||
abigail-dantes | 0 | 84,962,795,505 | 5% | ||
leczy | 0 | 326,272,562 | 5% | ||
ovij | 0 | 733,018,359 | 5% | ||
suravsingh | 0 | 64,017,199 | 5% | ||
joseg | 0 | 69,363,090 | 3% | ||
mountain.phil28 | 0 | 2,505,635,834 | 30% | ||
akeelsingh | 0 | 184,797,782 | 5% | ||
felixrodriguez | 0 | 119,183,183 | 2.5% | ||
pearlumie | 0 | 1,866,152,820 | 5% | ||
tormiwah | 0 | 235,019,674 | 1.5% | ||
ksolymosi | 0 | 962,586,851 | 5% | ||
simplifylife | 0 | 754,279,589 | 2.5% | ||
mayowadavid | 0 | 411,966,798 | 2.5% | ||
enzor | 0 | 85,443,918 | 2.5% | ||
carloserp-2000 | 0 | 908,338,537 | 5% | ||
pangoli | 0 | 424,146,204 | 5% | ||
rachelsmantra | 0 | 214,559,082 | 5% | ||
gra | 0 | 1,880,733,872 | 5% | ||
utopian-io | 0 | 14,848,245,385,338 | 10.28% | ||
azwarrangkuti | 0 | 31,407,562,922 | 50% | ||
kenadis | 0 | 1,355,423,592 | 5% | ||
amavi | 0 | 780,704,831 | 1% | ||
robotics101 | 0 | 199,986,838 | 4% | ||
gentleshaid | 0 | 1,146,875,478 | 5% | ||
sco | 0 | 172,517,602 | 0.25% | ||
adetola | 0 | 185,797,014 | 5% | ||
dysfunctional | 0 | 222,548,906 | 2.5% | ||
whileponderin | 0 | 107,940,678 | 5% | ||
hadji | 0 | 243,120,157 | 5% | ||
sakura1012 | 0 | 120,604,663 | 5% | ||
iamankit | 0 | 3,616,896,454 | 100% | ||
terrylovejoy | 0 | 367,537,932 | 1.25% | ||
princewrites | 0 | 1,221,578,522 | 100% | ||
rionpistorius | 0 | 105,771,665 | 2.5% | ||
deutsch-boost | 0 | 372,789,133 | 20% | ||
josephace135 | 0 | 7,420,027,272 | 50% | ||
amn | 0 | 0 | 100% | ||
dexterdev | 0 | 1,036,567,767 | 5% | ||
ugonma | 0 | 72,451,024 | 5% | ||
drkomoo | 0 | 61,750,060 | 5% | ||
alexdory | 0 | 608,428,611 | 5% | ||
reazuliqbal | 0 | 5,156,205,894 | 100% | ||
pseudojew | 0 | 84,046,426 | 5% | ||
effofex | 0 | 55,493,862 | 2.5% | ||
ayay | 0 | 53,110,924 | 11% | ||
de-stem | 0 | 220,916,897 | 0.5% | ||
hatuvera | 0 | 203,995,128 | 10% | ||
biomimi | 0 | 229,444,877 | 40% | ||
pruthuudeshi | 0 | 586,746,909 | 100% |
<p>Congratulations! This post has been upvoted from the communal account, @minnowsupport, by amn from the Minnow Support Project. It's a witness project run by aggroed, ausbitbank, teamsteem, theprophet0, someguy123, neoxian, followbtcnews, and netuoso. The goal is to help Steemit grow by supporting Minnows. Please find us at the <a href="https://discord.gg/HYj4yvw"> Peace, Abundance, and Liberty Network (PALnet) Discord Channel</a>. It's a completely public and open space to all members of the Steemit community who voluntarily choose to be there.</p> <p>If you would like to delegate to the Minnow Support Project you can do so by clicking on the following links: <a href="https://v2.steemconnect.com/sign/delegateVestingShares?delegator=&delegatee=minnowsupport&vesting_shares=102530.639667%20VESTS">50SP</a>, <a href="https://v2.steemconnect.com/sign/delegateVestingShares?delegator=&delegatee=minnowsupport&vesting_shares=205303.639667%20VESTS">100SP</a>, <a href="https://v2.steemconnect.com/sign/delegateVestingShares?delegator=&delegatee=minnowsupport&vesting_shares=514303.639667%20VESTS">250SP</a>, <a href="https://v2.steemconnect.com/sign/delegateVestingShares?delegator=&delegatee=minnowsupport&vesting_shares=1025303.639667%20VESTS">500SP</a>, <a href="https://v2.steemconnect.com/sign/delegateVestingShares?delegator=&delegatee=minnowsupport&vesting_shares=2053030.639667%20VESTS">1000SP</a>, <a href="https://v2.steemconnect.com/sign/delegateVestingShares?delegator=&delegatee=minnowsupport&vesting_shares=10253030.639667%20VESTS">5000SP</a>. <br><strong>Be sure to leave at least 50SP undelegated on your account.</strong></p>
author | minnowsupport |
---|---|
permlink | re-how-to-upload-images-in-ruby-on-rails-using-paperclip-20180411t174553 |
category | utopian-io |
json_metadata | "" |
created | 2018-04-11 17:46:00 |
last_update | 2018-04-11 17:46:00 |
depth | 1 |
children | 0 |
last_payout | 2018-04-18 17:46:00 |
cashout_time | 1969-12-31 23:59:59 |
total_payout_value | 0.000 HBD |
curator_payout_value | 0.000 HBD |
pending_payout_value | 0.000 HBD |
promoted | 0.000 HBD |
body_length | 1,699 |
author_reputation | 148,902,805,319,183 |
root_title | "How to upload images in ruby on rails using paperclip" |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 HBD |
percent_hbd | 10,000 |
post_id | 49,535,227 |
net_rshares | 0 |
### Hey @amn I am @utopian-io. I have just upvoted you! #### Achievements - You have less than 500 followers. Just gave you a gift to help you succeed! - Seems like you contribute quite often. AMAZING! #### Utopian Witness! <a href="https://discord.gg/zTrEMqB">Participate on Discord</a>. Lets GROW TOGETHER! - <a href="https://v2.steemconnect.com/sign/account-witness-vote?witness=utopian-io&approve=1">Vote for my Witness</a> - <a href="https://v2.steemconnect.com/sign/account-witness-proxy?proxy=utopian-io&approve=1">Proxy vote to Utopian Witness</a> **Up-vote this comment to grow my power and help Open Source contributions like this one. Want to chat? Join me on Discord https://discord.gg/Pc8HG9x**
author | utopian-io |
---|---|
permlink | re-amn-how-to-upload-images-in-ruby-on-rails-using-paperclip-20180411t122154483z |
category | utopian-io |
json_metadata | {"tags":["utopian-io"],"community":"utopian","app":"utopian/1.0.0"} |
created | 2018-04-11 12:21:57 |
last_update | 2018-04-11 12:21:57 |
depth | 1 |
children | 0 |
last_payout | 2018-04-18 12:21:57 |
cashout_time | 1969-12-31 23:59:59 |
total_payout_value | 0.000 HBD |
curator_payout_value | 0.000 HBD |
pending_payout_value | 0.000 HBD |
promoted | 0.000 HBD |
body_length | 708 |
author_reputation | 152,955,367,999,756 |
root_title | "How to upload images in ruby on rails using paperclip" |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 HBD |
percent_hbd | 10,000 |
post_id | 49,484,324 |
net_rshares | 0 |