<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Pascales Kurniawan on Medium]]></title>
        <description><![CDATA[Stories by Pascales Kurniawan on Medium]]></description>
        <link>https://medium.com/@pascales?source=rss-da3adcfabd85------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*1iZOkjTNsSjsxow1FqEIWQ.jpeg</url>
            <title>Stories by Pascales Kurniawan on Medium</title>
            <link>https://medium.com/@pascales?source=rss-da3adcfabd85------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 17 Nov 2026 02:02:05 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@pascales/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Simple Rails API Server using Simple TDD]]></title>
            <link>https://medium.com/binar-academy/simple-rails-api-server-using-simple-tdd-1a3dbeb3353a?source=rss-da3adcfabd85------2</link>
            <guid isPermaLink="false">https://medium.com/p/1a3dbeb3353a</guid>
            <category><![CDATA[ruby-on-rails]]></category>
            <category><![CDATA[tutorial]]></category>
            <category><![CDATA[beginners-guide]]></category>
            <dc:creator><![CDATA[Pascales Kurniawan]]></dc:creator>
            <pubDate>Sun, 21 Oct 2018 20:41:21 GMT</pubDate>
            <atom:updated>2018-12-05T19:48:56.114Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/611/1*ThTtzCi6UbYSvPonJ-3aMg.jpeg" /></figure><p><em>modified from </em><a href="https://scotch.io/tutorials/build-a-restful-json-api-with-rails-5-part-one"><em>https://scotch.io/tutorials/build-a-restful-json-api-with-rails-5-part-one</em></a></p><p>Hello, on this evening I want to share about how to create a simple rails API server using Test Driven Development Method.</p><p>TDD (Test Driven Development) is one approach that has grown on the Rails community. Although, not completely accepted by all in the community. This approach has you writing your test(s) first and then writing code to make your tests pass.</p><p>The goal of this article is creating a simple CRUD rails API server. I found out the tutorial on scotch.io is too advanced for a beginner so I decided to make it more simple for newbies. Okay let’s ride along..</p><p>We’re gonna create a set of endpoint which are:</p><p>Endpoints:<br>GET /articles<br>GET /articles/:id<br>POST /articles<br>PUT /articles/:id<br>DELETE /articles/:id</p><p>let’s create our app <em>$ rails new our_app_name -T -a --database=postgresql</em></p><p>We need to add these gems to our Gemfile.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e7acc7a62666a29fd998e04effc99de3/href">https://medium.com/media/e7acc7a62666a29fd998e04effc99de3/href</a></iframe><ul><li><a href="https://github.com/rspec/rspec-rails">rspec-rails</a> — Testing framework.</li><li><a href="https://github.com/thoughtbot/factory_bot_rails">factory_bot_rails</a> — A fixtures replacement with a more straightforward syntax. You’ll see.</li><li><a href="https://github.com/thoughtbot/shoulda-matchers">shoulda_matchers</a> — Provides RSpec with additional matchers.</li><li><a href="https://github.com/DatabaseCleaner/database_cleaner">database_cleaner</a> — You guessed it! It literally cleans our test database to ensure a clean state in each test suite.</li><li><a href="https://github.com/stympy/faker">faker</a> — A library for generating fake data. We’ll use this to generate test data.</li></ul><p>after installing our gems with<em> $ bundle install </em>then we do <em>$ rails generate rspec:install , </em>This adds the following files which are used for configuration:</p><ul><li>.rspec</li><li>spec/spec_helper.rb</li><li>spec/rails_helper.rb</li></ul><p>Let’s modify spec/rails_helper.rb to configure our gems.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b3106e2264fbe34ab9f20ecf5de3e38f/href">https://medium.com/media/b3106e2264fbe34ab9f20ecf5de3e38f/href</a></iframe><h3>MODEL</h3><p>We can start creating our Article model by executing <em>$ rails generate model article title:string content:text.</em></p><p>After creating the database $rails db:create, then run migration <em>$ rails db:migrate.</em></p><p>We’re gonna write our Model test in spec/model/article_spec.rb, on this step we use shoulda matchers gem for our model test.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c30ecdcca216468a89eaa38011cd2dd2/href">https://medium.com/media/c30ecdcca216468a89eaa38011cd2dd2/href</a></iframe><p>Then run rspec <em>$ bundle exec rspec </em>and the Test is surely failling.</p><p>Lets Fix it , modifying app/model/article.rb.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f70121fccd9b744c17a4b73880c9254d/href">https://medium.com/media/f70121fccd9b744c17a4b73880c9254d/href</a></iframe><p>run <em>$ bundle exec rspec</em> again, and model test error is gone.</p><p>Lets create our test data using Faker gem, define spec/factories/article.rb and By wrapping faker methods in a block, we ensure that faker generates dynamic data every time the factory is invoked.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/449b2dbdceea4199456ba1996d9d51ab/href">https://medium.com/media/449b2dbdceea4199456ba1996d9d51ab/href</a></iframe><h3>CONTROLLER</h3><p>Okay, let’s create our articles controller by running <em>$ rails generate controller article.</em></p><p>We use request spec since we’re gonna test an api controller as stated on <a href="https://github.com/rspec/rspec-rails">https://github.com/rspec/rspec-rails</a>.</p><blockquote>Use request specs to describe the client-facing behavior of the application — specifically, the HTTP response to be issued for a given request (a.k.a. integration tests). Since such client-facing behavior encompasses controller actions, this is the type of spec to use for controller testing.</blockquote><p>Now create our test suite on spec/request/article_spec.rb.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/8e9b2f76fa91b7abfc7b17dcdcf6afb0/href">https://medium.com/media/8e9b2f76fa91b7abfc7b17dcdcf6afb0/href</a></iframe><p>We initialize 10 test data using faker gem, and we’re also using json helper that defined in spec/support/article_spec_helper.rb.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/8ba95d3d322e6e78624c5fb2eafd0795/href">https://medium.com/media/8ba95d3d322e6e78624c5fb2eafd0795/href</a></iframe><p>To enable support directory, let’s modify spec/rails_helper.rb file.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/07c014478fd4ff724ee4af10fd9db8cf/href">https://medium.com/media/07c014478fd4ff724ee4af10fd9db8cf/href</a></iframe><p>Run the test and we’ve got a lot of error, let’s fix routing error first.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/105ad8e880f78ea9497772e4402a0ec4/href">https://medium.com/media/105ad8e880f78ea9497772e4402a0ec4/href</a></iframe><p>Finally we’re going to define our Articles controller.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/2ecdf14967bcd363ecb137f214b6f001/href">https://medium.com/media/2ecdf14967bcd363ecb137f214b6f001/href</a></iframe><p>We use json_response.rb and exception_handler.rb helper, let’s define it.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a0ed93e9a8b3fd46c0d77887d1b821c8/href">https://medium.com/media/a0ed93e9a8b3fd46c0d77887d1b821c8/href</a></iframe><p>Include helpers file to application_controller.rb so our controller will know it.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/70b420b5ade60961914b4f00257ede25/href">https://medium.com/media/70b420b5ade60961914b4f00257ede25/href</a></iframe><p>Run the test, we’ve got all green! (Hopefully)</p><p>That’s it!</p><p>You can find the repo here: <a href="https://github.com/pascalesdedy/latihan-rails-api-TDD">https://github.com/pascalesdedy/latihan-rails-api-TDD</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1a3dbeb3353a" width="1" height="1" alt=""><hr><p><a href="https://medium.com/binar-academy/simple-rails-api-server-using-simple-tdd-1a3dbeb3353a">Simple Rails API Server using Simple TDD</a> was originally published in <a href="https://medium.com/binar-academy">Binar Academy</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Cara Sederhana Mengelola Codebase dengan Github]]></title>
            <link>https://medium.com/binar-academy/github-14060f257af1?source=rss-da3adcfabd85------2</link>
            <guid isPermaLink="false">https://medium.com/p/14060f257af1</guid>
            <category><![CDATA[github]]></category>
            <category><![CDATA[tutorial]]></category>
            <category><![CDATA[beginners-guide]]></category>
            <dc:creator><![CDATA[Pascales Kurniawan]]></dc:creator>
            <pubDate>Thu, 23 Aug 2018 21:25:26 GMT</pubDate>
            <atom:updated>2018-12-05T19:52:27.952Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*c3DlhZetqdKLtoTO6oYURw.png" /></figure><p>Hello gaes,</p><p>Hari ini saya akan membahas sedikit tentang Github, apa itu Github?</p><blockquote><strong>GitHub</strong> adalah <a href="https://id.wikipedia.org/wiki/Layanan_penginangan_web">layanan penginangan web</a> bersama untuk proyek pengembangan <a href="https://id.wikipedia.org/wiki/Perangkat_lunak">perangkat lunak</a> yang menggunakan sistem <a href="https://id.wikipedia.org/wiki/Pengontrol_versi">pengontrol versi</a> <a href="https://id.wikipedia.org/wiki/Git">Git</a> dan <a href="https://id.wikipedia.org/wiki/Layanan_hosting_internet">layanan hosting internet</a>. Hal ini banyak digunakan untuk kode komputer. Ini memberikan kontrol akses dan beberapa fitur kolaborasi seperti pelacakan bug, permintaan fitur, manajemen tugas, dan <a href="https://id.wikipedia.org/wiki/Wiki">wiki</a> untuk setiap proyek. ~wikipedia</blockquote><p>Nah, hari ini kita akan mencoba sebuah prosedur sederhana untuk mengelola codebase dari Project kita.</p><h3>Inisialisasi</h3><p>Saat kita memulai sebuah project, pertama kali yang kita lakukan adalah membuat sebuah <em>repository</em> baru, setelah itu kita siapkan atau kita buat readme.MD</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*WmifjJw_hF9OpEJkGAFsHA.png" /><figcaption>create new repository</figcaption></figure><h3>Kolaborators</h3><p>Setelah itu kita bisa mulai meng-<em>invite</em> rekan-rekan kolaborator, dan jangan lupa untuk mengeset Access Right kolaborator dan menentukan siapa saja yang mempunyai akses untuk <em>merge</em>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*JWt1iomjhAQFnTsSHkXNig.png" /><figcaption>collaborators</figcaption></figure><h3>Fork</h3><p>Setiap kolaborator mempunyai repository sendiri sendiri dan dapat bekerja secara mandiri. Kita <em>push</em> kode kita ke origin/branch-name dan kemudian akan di-<em>merge</em> ke <em>branch</em>/develop.</p><h3>Branching</h3><p>Ada beberapa branch name yang umum digunakan dalam github</p><ol><li>master - adalah <em>branch</em> yg digunakan untuk Production deployment</li><li>develop - adalah <em>branch</em> yang digunakan untuk menyatukan/menggabungkan <em>feature</em> dari rekan-rekan kolaborator</li><li>staging - adalah <em>branch</em> yang kita gunakan untuk mengetes <em>feature</em>, setelah lolos <em>functional test</em> dan <em>QA test</em>, maka <em>branch</em> ini siap di-<em>merge</em> ke <em>branch</em> master untuk <em>deployment</em> ke Production Env</li><li>branch lainnya — Jika ada rekan kolaborator yang keluar/berhenti dan tidak melanjutkan project, maka sebaiknya repo kolaborator tersebut diberi nama ,collaborators_name/feature/feature_name. agar bisa dilanjutkan oleh rekan-rekan yang lainnya</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Ch8XcFTFAcYVrBJi-BD2IA.png" /><figcaption>Branching</figcaption></figure><p>Berikut adalah contoh dari penamaan <em>branch</em> untuk memudahkan kita mengidentifikasi <em>branch</em></p><ol><li>Untuk sebuah feature, feature/new-editor.</li><li>Untuk sebuah bug, bug/time-zone-fix.</li><li>Untuk issue, issue/:issue_number/issue-description.</li></ol><p>Mudah bukan? semoga bermanfaat..</p><p><em>Disadur dari berbagai sumber, selengkapnya kunjungi: </em><a href="https://help.github.com/"><em>https://help.github.com/</em></a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=14060f257af1" width="1" height="1" alt=""><hr><p><a href="https://medium.com/binar-academy/github-14060f257af1">Cara Sederhana Mengelola Codebase dengan Github</a> was originally published in <a href="https://medium.com/binar-academy">Binar Academy</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Delivering static images through a CDN]]></title>
            <link>https://medium.com/binar-academy/delivering-static-images-through-a-cdn-7f67ea6c3f?source=rss-da3adcfabd85------2</link>
            <guid isPermaLink="false">https://medium.com/p/7f67ea6c3f</guid>
            <category><![CDATA[ruby-on-rails]]></category>
            <category><![CDATA[beginners-guide]]></category>
            <category><![CDATA[notes-to-self]]></category>
            <category><![CDATA[cloudinary]]></category>
            <dc:creator><![CDATA[Pascales Kurniawan]]></dc:creator>
            <pubDate>Fri, 10 Aug 2018 22:29:18 GMT</pubDate>
            <atom:updated>2018-08-13T14:57:51.015Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*WDuVMoOLfsi2lf5Y64EKrg.png" /><figcaption>Delivering static images through a CDN</figcaption></figure><p>Good Morning,</p><p>This time I want to share about using cloudinary to store our static images/assets, we need this if we want to deploy our app to heroku free account 😛 , I assume that you are already have a cloudinary account, if you don’t, you can create it <a href="https://cloudinary.com/">here</a>.</p><p>First of all , add cloudinary gem to your gemfile</p><pre>gem ‘cloudinary’</pre><p>then run bundle install</p><p>download your cloudinary.yml file <a href="https://cloudinary.com/console/cloudinary.yml">here</a> and put it on your app/config directory</p><p>to upload all your Ruby-on-Rails applications’ static images to Cloudinary, run:</p><pre>rake cloudinary:sync_static</pre><p>This Rake task finds all the images in all common public folders and in Rails <strong>Asset Pipeline</strong>’s image asset folders. Afterwards, it uploads all new and modified images to Cloudinary.</p><p>When you add new static images or change existing ones, all you need to do is re-run ‘rake cloudinary:sync_static’.</p><p>That’s it folks.. 😃</p><p>for more details please visit:</p><ol><li><a href="https://cloudinary.com/blog/how_to_deliver_your_static_images_through_a_cdn_in_ruby_on_rails">https://cloudinary.com/blog/how_to_deliver_your_static_images_through_a_cdn_in_ruby_on_rails</a></li><li><a href="https://cloudinary.com/documentation/rails_integration#getting_started">https://cloudinary.com/documentation/rails_integration#getting_started</a></li></ol><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7f67ea6c3f" width="1" height="1" alt=""><hr><p><a href="https://medium.com/binar-academy/delivering-static-images-through-a-cdn-7f67ea6c3f">Delivering static images through a CDN</a> was originally published in <a href="https://medium.com/binar-academy">Binar Academy</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Deploying Rails App on Openshift Kubernetes Cluster]]></title>
            <link>https://medium.com/binar-academy/deploying-rails-app-on-openshift-kubernetes-cluster-80801f620c91?source=rss-da3adcfabd85------2</link>
            <guid isPermaLink="false">https://medium.com/p/80801f620c91</guid>
            <category><![CDATA[tutorial]]></category>
            <category><![CDATA[ruby-on-rails]]></category>
            <category><![CDATA[beginners-guide]]></category>
            <category><![CDATA[openshift]]></category>
            <dc:creator><![CDATA[Pascales Kurniawan]]></dc:creator>
            <pubDate>Tue, 24 Jul 2018 19:55:24 GMT</pubDate>
            <atom:updated>2018-12-05T19:58:23.039Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*HkFCyNiosjBDqtT9UhGRug.png" /></figure><p>Halo..</p><p>Kali ini saya akan membagikan cara deploy rails app on Openshift kubernetes cluster, Pascales-way. Mengapa Pascales-way? Karena tutorial yang saya dapat dari <a href="https://github.com/sclorg/rails-ex">sini</a> masih terlalu rumit buat saya yang noob ini. Jadi seandainya Anda mencoba mengikuti langkah langkah saya, resiko ditanggung penumpang njih hehehe.</p><p>Okay kita mulai,<br>1. Create Free Account di Openshift.com, Anda akan mendapatkan 1GiB Memory, 1 GiB presistent storage, 1 GiB terminating memory dan community support</p><p>2. Instal oc-CLI di <a href="https://docs.openshift.org/latest/cli_reference/get_started_cli.html">https://docs.openshift.org/latest/cli_reference/get_started_cli.html</a></p><p>3. Setelah create account, kemudian click “open web console”</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4N0KwDslgUpvYq_ZfXUL3Q.png" /></figure><p>4. Pilih dari Ruby+postgreSQL dari Browse Catalog (untuk free account hanya diijinkan untuk memiliki 1 project saja)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*iVdPm5rbAwYIvp2jj37sBQ.png" /></figure><p>5. Ikuti steps nya</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Dz3nV14JhrtC0NSexiCdug.png" /></figure><p>pada field Git repository URL, biarkan saja default (<a href="https://github.com/openshift/rails-ex.git">https://github.com/openshift/rails-ex.git</a> )</p><p>6. Setelah itu, login ke github.com dan kemudian clone/download sample app dari openshift <a href="https://github.com/openshift/rails-ex.git">https://github.com/openshift/rails-ex.git</a></p><p>7. Kemudian kembali ke Openshift web console, Build section ~&gt; configuration, kemudian gantilah source repo ke source repo yang baru saja di clone/download, misal <a href="https://github.com/openshift/rails-ex.git">https://github.com/nama-anda/rails-ex.git</a></p><p>8. Copy Github webhook URL yang terdapat dibagian sebelah kanan halaman.</p><p>9. Kembali ke <a href="https://github.com/openshift/rails-ex.git">https://github.com/nama-anda/rails-ex.git</a> buka setting ~&gt; webhook ~&gt; add webhook. paste di Payload URL, save.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*b8RD5ierdIM5__lb_IycDg.png" /></figure><p>10. Kemudian clone repo github anda <br><em>$ git clone </em><a href="https://github.com/openshift/rails-ex.git"><em>https://github.com/nama-anda/rails-ex.git</em></a></p><p>11. Cd ke folder rails-ex lakukan bundle install, kemudian rails db:migrate</p><p>12. Cek error message di terminal untuk mengetahui nama database yg belum dibuat, misal : <br><em>pascales $ rails db:migrate<br>rails aborted!<br>ActiveRecord::NoDatabaseError: FATAL: database </em><strong><em>“pascales”</em></strong><em> does not exist</em></p><p>13. Lanjutkan dengan create database dengan nama yang diminta, lanjutkan lagi dengan rails <em>db:migrate</em></p><p>14. Jalankan rails server</p><p>15. Buka web browser pergi ke localhost:3000</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*OyJkfDO83V0iqdmj9lTl6g.png" /><figcaption>public/index.html</figcaption></figure><p>16. Nah, menggunakan text editor anda, buka welcome_controller.rb didalam sample app tadi, hapus line : <em>render :file =&gt; ‘public/index.html’ </em>maka rails akan me render views/index.html.erb</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*KkPDNQuiaXL4V01udo_CAA.png" /><figcaption>welcome_controller.rb</figcaption></figure><p>17. Restart rails server, dan reload localhost:3000 lagi</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*npE6DJQuqf2ogQU2XWRApQ.png" /><figcaption>localhost:3000</figcaption></figure><p>18. oke sekarang sample app nya sudah berjalan di local, langkah berikutnya adalah git add, comit kemudian push ke master di github yang secara otomatis akan terdeploy ke Openshift melalui webhook yg sudah kita set up tadi.</p><p>19. Cek di Openshift</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*eBeDf_9_tWeyXJ3P8CbyXA.png" /></figure><p>21. Nah, sekarang sudah sinkron. Silakan buka folder rails-ex dan mulai bangun aplikasi Anda.</p><p>Wah panjang beud yah. Mudah-mudahan tidak ada yang terlewatkan. Honestly saya belum terlalu menguasai ini dan masih perlu banyak belajar. So, sekali lagi resiko ditanggung penumpang yah hehe.</p><p>Cheers!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=80801f620c91" width="1" height="1" alt=""><hr><p><a href="https://medium.com/binar-academy/deploying-rails-app-on-openshift-kubernetes-cluster-80801f620c91">Deploying Rails App on Openshift Kubernetes Cluster</a> was originally published in <a href="https://medium.com/binar-academy">Binar Academy</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Social Login: Login with Google Account]]></title>
            <link>https://medium.com/binar-academy/social-login-login-with-google-account-4b10224494ac?source=rss-da3adcfabd85------2</link>
            <guid isPermaLink="false">https://medium.com/p/4b10224494ac</guid>
            <category><![CDATA[tutorial]]></category>
            <category><![CDATA[ruby-on-rails]]></category>
            <category><![CDATA[oauth2]]></category>
            <category><![CDATA[beginners-guide]]></category>
            <dc:creator><![CDATA[Pascales Kurniawan]]></dc:creator>
            <pubDate>Mon, 23 Jul 2018 20:50:28 GMT</pubDate>
            <atom:updated>2018-07-24T06:14:43.234Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*B_qiJIL70opWRtKSyiCY3g.png" /></figure><p>Hello there..<br>In this article I would share about creating user login with devise and their Google account. I assume that you already know how to integrate devise with your rails application.</p><h3><strong>Devise installation</strong></h3><p>Add to your Gemfile</p><pre>gem &quot;devise&quot;</pre><p>then do:</p><pre>$ bundle install<br>$ rails generate devise:install<br>$ rails generate devise MODEL_NAME</pre><p>Replace MODEL_NAME with User if you have User as your model name, then you should create/modify your Views and Controller accordingly</p><h3>OmniAuth Google OAuth2 Installation</h3><p>Add to your Gemfile</p><pre>gem &quot;omniauth-google-oauth2&quot;</pre><p>then run bundle install</p><p>Define your application id and secret in config/initializers/devise.rb</p><pre>config.omniauth :google_oauth2, &quot;GOOGLE_CLIENT_ID&quot;, &quot;GOOGLE_CLIENT_SECRET&quot;, { }</pre><p>get your GOOGLE_CLIENT_ID and GOOGLE_CLIENT_SECRET :</p><ul><li>Go to <a href="https://console.developers.google.com/">https://console.developers.google.com</a></li><li>Create your project.</li><li>Click ‘Enable and manage APIs’.</li><li>Make sure “Contacts API” and “Google+ API” are on.</li><li>Click Create credentials</li><li>on Where will you be calling the API from? choose “web server”</li><li>on What data will you be accessing? choose “user data”</li><li>Type <a href="http://localhost:3000/users/auth/google_oauth2/callback">http://localhost:3000/users/auth/google_oauth2/callback</a> in Authorized redirect URIs ( for development, change it if you’re on Production)</li><li>Then Click Oauth Client ID</li><li>provide an ‘EMAIL ADDRESS’ and a ‘PRODUCT NAME’</li><li>then download Credentials</li><li>You can findGOOGLE_CLIENT_ID, GOOGLE_CLIENT_SECRET in your downloaded credential json file.</li></ul><p>Then add the following to config/routes.rb to define callback routes.</p><pre>devise_for :users, :controllers =&gt; { :omniauth_callbacks =&gt; &quot;users/omniauth_callbacks&quot; }</pre><p>Create call back controller file app/controller/user/omniauth_callbacks_controller.rb and enter these lines</p><pre>class Users::OmniauthCallbacksController &lt; Devise::OmniauthCallbacksController<br>  def google_oauth2<br>      @user = User.from_omniauth(request.env[&quot;omniauth.auth&quot;])<br>      if @user.persisted?<br>        flash[:notice] = I18n.t &quot;devise.omniauth_callbacks.success&quot;, :kind =&gt; &quot;Google&quot;<br>        sign_in_and_redirect @user, :event =&gt; :authentication<br>      else<br>        session[&quot;devise.google_data&quot;] = request.env[&quot;omniauth.auth&quot;]<br>        redirect_to new_user_registration_url<br>      end<br>  end<br>end</pre><p>and these on your model app/models/user.rb</p><pre>def self.from_omniauth(access_token)<br>  data = access_token.info<br>  user = User.where(:email =&gt; data[&quot;email&quot;]).first<br><br>  unless user<br>    password = Devise.friendly_token[0,20]<br>    user = User.create(name: data[&quot;name&quot;], email: data[&quot;email&quot;],<br>      password: password, password_confirmation: password<br>    )<br>  end<br>  user<br>end</pre><p>and finally on your views, you can login using:</p><pre>&lt;%= link_to &quot;Sign in with Google&quot;, user_google_oauth2_omniauth_authorize_path %&gt;</pre><p>you can dig deeper on gem’s github repo : <a href="https://github.com/zquestz/omniauth-google-oauth2">https://github.com/zquestz/omniauth-google-oauth2</a></p><p>Have a nice day…</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4b10224494ac" width="1" height="1" alt=""><hr><p><a href="https://medium.com/binar-academy/social-login-login-with-google-account-4b10224494ac">Social Login: Login with Google Account</a> was originally published in <a href="https://medium.com/binar-academy">Binar Academy</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[My Journey]]></title>
            <link>https://medium.com/binar-academy/my-journey-a16658d1276e?source=rss-da3adcfabd85------2</link>
            <guid isPermaLink="false">https://medium.com/p/a16658d1276e</guid>
            <category><![CDATA[binar-academy]]></category>
            <category><![CDATA[ruby-on-rails]]></category>
            <category><![CDATA[citrakara]]></category>
            <dc:creator><![CDATA[Pascales Kurniawan]]></dc:creator>
            <pubDate>Tue, 17 Jul 2018 19:57:26 GMT</pubDate>
            <atom:updated>2018-07-20T09:52:56.073Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*BAjGnzMQSJZDD_fvJ4OgDQ.jpeg" /></figure><p>Salah satu hobi saya adalah belajar komputer programming, mungkin Anda menganggap ini adalah hobi yang sangat naif, tapi kenyataannya memang seperti itu. Saya sangat suka dengan segala hal yang berbau teknologi dan komputer programming adalah salah satu alat yang membangun sebuah teknologi baru.</p><p>Perkenalan saya dengan Binar dimulai sekitar bulan November 2017, ketika itu sahabat saya bercerita tentang Binar Academy, dan saya langsung tertarik, apalagi ketika saya mengetahui bahwa belajar di Binar Academy tidak dipungut biaya alias GRATIS!! Saya pun mulai mencari informasi bagaimana cara mengikuti Binar Academy dan setelah itu saya pun <a href="http://binar.co.id/">mendaftar di Binar Academy</a>, motivasi saya selain memang belajar adalah hobi saya, saya juga ingin mengembangkan karir.</p><p>Setelah menunggu beberapa bulan akhirnya batch#7 dimulai pada akhir April 2018, perjalanan belajar di Binar Academy dimulai dengan Induction Meeting yang dilaksanakan di Savita Inn. Saat itu saya mengambil kelas QA namun ketika Induction Meeting dijelaskan bahwa Kelas BackEnd menggunakan Ruby sebagai bahasa pemrograman maka saya langsung request untuk pindah ke kelas Back End, Why? Karena saya memang ingin mendalami Ruby, saya sudah cukup lelah dengan QA yang selama 5 tahun sudah saya jalani.</p><p>Banyak hal yang saya pelajari dari Binar Academy. Yang pertama dan yang pasti adalah Ruby programming. Kedua, saya banyak belajar tentang Software Development Lifecycle yang selama ini masih sebatas teori yang saya baca di internet namun di Binar Academy kita melakukan hal itu. Ketiga, saya banyak belajar tentang bagaimana menjalin relasi yang baik dengan para siswa Binar Academy yang rata-rata masih muda, berbeda jauh dengan umur saya yang sudah di mid 30 dan saya ditunjuk sebagai tech lead oleh PM tim saya sehingga saya dituntut untuk bisa meng-handle divisi Backend.</p><p>Proses belajar di Binar Academy diakhiri dengan Showcase di depan para Partner Binar. Kita melakukan presentasi tentang aplikasi yang kita buat di depan para partner binar. Saya merasa senang, bangga, gugup, semangat, semua bercampur jadi satu , sangat luar biasa.</p><p>Akhir kata, You’re all awesome !! and see you on top !!</p><blockquote>“In times of change, learners inherit the earth, while the learned find themselves beautifully equipped, to deal with a world that no longer exists.” -Eric Hoffer</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*SmM_h7JSgNDkOSPcoNi7FA.jpeg" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a16658d1276e" width="1" height="1" alt=""><hr><p><a href="https://medium.com/binar-academy/my-journey-a16658d1276e">My Journey</a> was originally published in <a href="https://medium.com/binar-academy">Binar Academy</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Creating “Forgot password” feature on Rails API]]></title>
            <link>https://medium.com/binar-academy/forgot-password-feature-on-rails-api-8e4a7368c59?source=rss-da3adcfabd85------2</link>
            <guid isPermaLink="false">https://medium.com/p/8e4a7368c59</guid>
            <category><![CDATA[rails-api]]></category>
            <category><![CDATA[notes-to-self]]></category>
            <category><![CDATA[authentication]]></category>
            <category><![CDATA[ruby-on-rails]]></category>
            <dc:creator><![CDATA[Pascales Kurniawan]]></dc:creator>
            <pubDate>Tue, 19 Jun 2018 01:59:22 GMT</pubDate>
            <atom:updated>2018-07-20T09:55:52.411Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/817/1*uDOM0ht4KdZbR1FKFMVWdA.png" /></figure><p>Just a small note for myself…</p><p>Hello, today I want to share about common feature that always can be found on a login page, a “Forgot password” feature. The flow is simple, user that forgot his password clicks the “forgot password” link, then the user should input email address he was registered with. After that a token is sent to the email address. User then sends the token along with the new password, after it is successfuly sent, the password then resetted.</p><p>okay, first thing first, let’s generate migration to add reset_password_token and reset_password_sent_at column to your user table</p><p>rails g migration AddPasswordResetColumnsToUser</p><pre>add_column :users, :reset_password_token, :string<br>add_column :users, :reset_password_sent_at, :datetime</pre><p>then we should create password controller for our forgot password methods.</p><p>rails g controller passwords</p><p>add endpoints for forgot password and reset password in our routes.rb file</p><pre><strong>config/routes.rb:</strong></pre><pre>post &#39;password/forgot&#39;, to: &#39;password#forgot&#39;<br>post &#39;password/reset&#39;, to: &#39;password#reset&#39;</pre><p>let’s add these codes to our passwords_controller</p><pre><strong>controllers/passwords_controller.rb</strong>:</pre><pre>...<br>  def forgot<br>    if params[:email].blank? # check if email is present<br>      return render json: {error: &#39;Email not present’}<br>    end<br><br>    user = User.find_by(email: params[:email]) # if present find user by email<br><br>    if user.present?<br>      user.generate_password_token! #generate pass token<br>      # SEND EMAIL HERE<br>      render json: {status: &#39;ok’}, status: :ok<br>    else<br>      render json: {error: [’Email address not found. Please check and try again.’]}, status: :not_found<br>    end<br>  end<br><br>  def reset<br>    token = params[:token].to_s<br><br>    if params[:email].blank?<br>      return render json: {error: &#39;Token not present’}<br>    end<br><br>    user = User.find_by(reset_password_token: token)<br><br>    if user.present? &amp;&amp; user.password_token_valid?<br>      if user.reset_password!(params[:password])<br>        render json: {status: &#39;ok’}, status: :ok<br>      else<br>        render json: {error: user.errors.full_messages}, status: :unprocessable_entity<br>      end<br>    else<br>      render json: {error:  [’Link not valid or expired. Try generating a new link.’]}, status: :not_found<br>    end<br>  end<br> ...<br></pre><p>I skip the email generation section, you can find how to send the email on my <a href="https://medium.com/@pascales/welcome-email-for-new-user-using-action-mailer-becdb43ee6a">previous</a> article.</p><p>okay, does the codes work ? not yet… let’s add some methods to our user model.</p><pre><strong>models/user.rb</strong></pre><pre>...<br>def generate_password_token!<br> self.reset_password_token = generate_token<br> self.reset_password_sent_at = Time.now.utc<br> save!<br>end<br><br>def password_token_valid?<br> (self.reset_password_sent_at + 4.hours) &gt; Time.now.utc<br>end<br><br>def reset_password!(password)<br> self.reset_password_token = nil<br> self.password = password<br> save!<br>end<br><br>private<br><br>def generate_token<br> SecureRandom.hex(10)<br>end<br>...</pre><p>That’s it, you can test it via postman:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/605/1*tQ87R5NG2mub2GTg3JbwMw.png" /></figure><p>If you have any suggestion or correction, please feel free to put it in response bellow, have a nice day….</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8e4a7368c59" width="1" height="1" alt=""><hr><p><a href="https://medium.com/binar-academy/forgot-password-feature-on-rails-api-8e4a7368c59">Creating “Forgot password” feature on Rails API</a> was originally published in <a href="https://medium.com/binar-academy">Binar Academy</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[“Welcome email” for new user using Action Mailer]]></title>
            <link>https://pascales.medium.com/welcome-email-for-new-user-using-action-mailer-becdb43ee6a?source=rss-da3adcfabd85------2</link>
            <guid isPermaLink="false">https://medium.com/p/becdb43ee6a</guid>
            <category><![CDATA[mail]]></category>
            <category><![CDATA[ruby-on-rails]]></category>
            <category><![CDATA[beginners-guide]]></category>
            <dc:creator><![CDATA[Pascales Kurniawan]]></dc:creator>
            <pubDate>Sat, 09 Jun 2018 15:47:04 GMT</pubDate>
            <atom:updated>2018-06-09T15:47:04.162Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1023/1*Rl0J_66iqxLjWn18s2pHjA.png" /></figure><p>Hello gaes…</p><p>Today I want to share about sending email from rails application using Action mailer. Recently I worked on a project with my friend, and I wanted to add a feature that automatically send a new registered user a Welcome email…mmm.. No I was lying..haha. The truth is that I was trying to build a “forgot password” mechanism but I accidentally bumped to this feature.</p><p>anyway, let’s get on with it..</p><h3><strong>Generate and set up mailer</strong></h3><p>The first thing we should do is</p><pre>rails generate mailer UserMailer</pre><p>it will generate files that we need for sending mail. after that go to <em>app/mailers/application_mailer.rb</em> and change the value according to your mail account</p><pre># <em>app/mailers/application_mailer.rb</em></pre><pre>class ApplicationMailer &lt; ActionMailer::Base<br>  default from: <em>&quot;from@example.com&quot;<br>  </em>layout <em>&#39;mailer&#39;</em></pre><pre>end</pre><p>Okay then, open <em>app/mailers/user_mailer.rb </em>and add the method bellow</p><pre><em># app/mailers/user_mailer.rb</em></pre><pre>class UserMailer &lt; ApplicationMailer</pre><pre>def welcome_email(user)<br>    <strong>@user</strong> = user<em><br>    </em>mail(to: <strong>@user</strong>.email, subject: <em>&#39;Welcome to My Awesome Site&#39;</em>)<br>  end</pre><pre>end</pre><p>and again change the value as needed by your application.</p><p>Create the body of the email in <em>app/views/user_mailer/</em> name it <em>welcome_email.html.erb</em> and add these :</p><pre><em># app/views/user_mailer/welcome_email.html.erb</em></pre><pre>&lt;h1&gt;Welcome to example.com, &lt;%= <strong>@user</strong>.nickname %&gt;&lt;/h1&gt;<br>  &lt;p&gt;<br>    You have successfully signed up to example.com,<br>    your username is: &lt;%= <strong>@user</strong>.username %&gt;.&lt;br&gt;<br>  &lt;/p&gt;<br>&lt;p&gt;Thanks for joining and have a great day!&lt;/p&gt;</pre><p>customize it again according your application, it is basically a ruby html file so you can make it more attractive by adding some html codes</p><p>Add a text only version as well, in <em>app/views/user_mailer/</em> , create a file called welcome_email.text.erb</p><pre># <em>app/views/user_mailer/</em>welcome_email.text.erb</pre><pre>Welcome to example.com, &lt;%= <strong>@user</strong>.nickname %&gt;<br>===============================================</pre><pre>You have successfully signed up to example.com,<br>your username is: &lt;%= <strong>@user</strong>.username %&gt;.</pre><pre>Thanks for joining and have a great day!</pre><h3><strong>Gmail Configuration</strong></h3><p>Copy and paste the following into <em>config/environments/development.rb</em> ,</p><pre># <em>config/environments/development.rb<br></em>config.action_mailer.delivery_method = <strong>:sendmail</strong><br>config.action_mailer.perform_deliveries = true<br>config.action_mailer.raise_delivery_errors = true<br>config.action_mailer.default_options = {from: <em>&#39;no-reply@example.com&#39;</em>}</pre><p>Change the no-reply@example.com to your gmail account. Then copy and paste this part, which is specific for Gmail:</p><pre># <em>config/environments/development.rb<br></em>config.action_mailer.delivery_method = <strong>:smtp<br></strong>config.action_mailer.smtp_settings = {<br>address:              <em>&#39;smtp.gmail.com&#39;</em>,<br>port:                 587,<br>domain:               <em>&#39;example.com&#39;</em>,<br>user_name:            <em>&#39;&lt;username&gt;&#39;</em>,<br>password:             <em>&#39;&lt;password&gt;&#39;</em>,<br>authentication:       <em>&#39;plain&#39;</em>,<br>enable_starttls_auto: true  }</pre><h3>Send The mail</h3><p>Okay, after all set up correctly, we’re going to tell the mailer to send the mail by executing this</p><pre>UserMailer.welcome_email(<strong>@user</strong>).deliver_now</pre><p>We want to send the “Welcome email” after user is successfully registered, so we should put it on the create method in our users controller.</p><pre>def create<br> <a href="http://twitter.com/user">@user</a> = User.create(create_param)<br>     if <a href="http://twitter.com/user">@user</a>.save<br>        UserMailer.welcome_email(<a href="http://twitter.com/user">@user</a>).deliver_now<br>....</pre><p>Well done! we’re sending our new user a “Welcome email” to greet them.</p><h3>Problems with gmail account</h3><p>If you working with more than one application that using the same gmail account, probably you will see this issue:</p><pre>Net::SMTPAuthenticationError 535-5.7.8 Username and Password not accepted</pre><p>There are some possible causes:</p><ul><li>you have 2-step authentication setup on you gmail account</li><li>Your Gmail account is not valid</li><li>You have more than one application using the same gmail account.</li></ul><p><strong>Work around.</strong></p><ul><li>Disable 2-step authentication on your gmail account</li><li>Make sure your gmail account/password is valid</li><li>goto <a href="https://www.google.com/settings/security/lesssecureapps">https://www.google.com/settings/security/lesssecureapps</a> You should change the <em>“Access for less secure apps”</em> to Enabled (change it to disabled and than back to enabled). Also, bear in mind that it might take some times to enable the less secure apps. so be patient and wait for a while until they work</li></ul><p>You can use sendGrid, mailchimp or mailgun for mail server, its up to you but I use gmail account on my development environment.</p><p>Okay, If you have any <strong>correction or suggestion</strong>, please feel free to put it on responses bellow…</p><p>You can find more detail of Action mailer on:</p><p><a href="http://guides.rubyonrails.org/action_mailer_basics.html">Action Mailer Basics - Ruby on Rails Guides</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=becdb43ee6a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Integrating Forest CMS to Rails 5.2.0 API mode]]></title>
            <link>https://pascales.medium.com/integrating-forest-cms-to-rails-5-2-0-api-mode-1896983e0d4a?source=rss-da3adcfabd85------2</link>
            <guid isPermaLink="false">https://medium.com/p/1896983e0d4a</guid>
            <category><![CDATA[forest-cms]]></category>
            <category><![CDATA[tutorial]]></category>
            <category><![CDATA[beginners-guide]]></category>
            <category><![CDATA[ruby-on-rails]]></category>
            <dc:creator><![CDATA[Pascales Kurniawan]]></dc:creator>
            <pubDate>Sun, 03 Jun 2018 20:37:58 GMT</pubDate>
            <atom:updated>2018-06-04T14:39:07.117Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*p_67oP6OFiqY6mv9lBxRoQ.png" /><figcaption>Forest Admin Dashboard</figcaption></figure><p>Hello and good morning fellas, this time I want to share about Integrating forest CMS to your rails API application.</p><p>First thing to do is register yourself to forestadmin.com, after you’re successfully registered , create new project and <strong>follow the instruction on their website:</strong></p><pre>$ gem ‘forest_liana’<br>$ bundle install <br>$ rails g forest_liana:install 043dffa06b65148dcce93eeb93c9ec15a97163a3c5ed9747c19875b2160bbef8 <br>rails s <br></pre><p>Enter the URL of your application to check if Forest is well installed.</p><p><strong>The problem is, rails 5.2.0 won’t create <em>secrets.yml</em> file, it uses <em>credentials.yml.enc</em>, and it makes forest dashboard could not connect to your rails server.</strong></p><h3><strong>Work around:</strong></h3><ol><li>Create secrets.yml file inside app/config folder and paste the following codes:</li></ol><pre># app/config/secrets.yml</pre><pre># Be sure to restart your server when you modify this file.</pre><pre># Your secret key is used for verifying the integrity of signed cookies.<br># If you change this key, all old signed cookies will become invalid!</pre><pre># Make sure the secret is at least 30 characters and all random,<br># no regular words or you’ll be exposed to dictionary attacks.<br># You can use `rake secret` to generate a secure secret key.</pre><pre># Make sure the secrets in this file are kept private<br># if you’re sharing your code publicly.</pre><pre>development:<br> forest_env_secret: <br> forest_auth_secret: </pre><p>2. Install it again</p><pre>$ rails g forest_liana:install 043dffa06b65148dcce93eeb93c9ec15a97163a3c5ed9747c19875b2160bbef8</pre><p>3. Fired up your local server</p><pre>$ rails s</pre><p>4. Verify the installation on <a href="http://app.forestadmin.com/new-project">http://app.forestadmin.com/new-project</a></p><p>5. If your rails server is verified then you can go to Forest admin dashboard page</p><p>Thats it!</p><p>if you have any <strong>corrections or suggestion</strong>, please feel free to put it on comment bellow</p><p>Cheers! and have a nice day..</p><p>Links:<br><em>Forest admin website : </em><a href="https://www.forestadmin.com/"><em>https://www.forestadmin.com/</em></a></p><p><em>The official Rails liana for Forest repository : </em><a href="https://github.com/ForestAdmin/forest-rails"><em>https://github.com/ForestAdmin/forest-rails</em></a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1896983e0d4a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Carrierwave and Cloudinary for uploading images in Rails API]]></title>
            <link>https://medium.com/binar-academy/carrierwave-and-cloudinary-for-uploading-images-in-rails-api-ecfee7c5b973?source=rss-da3adcfabd85------2</link>
            <guid isPermaLink="false">https://medium.com/p/ecfee7c5b973</guid>
            <category><![CDATA[beginners-guide]]></category>
            <category><![CDATA[rails-api]]></category>
            <category><![CDATA[rails]]></category>
            <category><![CDATA[tutorial]]></category>
            <dc:creator><![CDATA[Pascales Kurniawan]]></dc:creator>
            <pubDate>Fri, 01 Jun 2018 14:44:16 GMT</pubDate>
            <atom:updated>2018-07-20T09:54:38.875Z</atom:updated>
            <content:encoded><![CDATA[<p>Hello, on this evening, I want to share about how to upload image to <a href="https://cloudinary.com/">Cloudinary</a>. As I quote on the Cloudinary site, <em>“Cloudinary is the media management platform for web and mobile developers,An end-to-end solution for all your image and video needs,”</em> and it’s free. Just register using your email no more hassle …</p><p>Okay first thing first , add carrierwave gem and cloudinary gem in your gemfile</p><pre>gem ‘carrierwave’<br>gem ‘cloudinary’</pre><p>then run <strong>bundle install</strong></p><p>after that, create cloudinary.yml on your ‘config’ folder, and put the security setting there.</p><pre># config/cloudinary.yml<br>development:<br>  cloud_name: &quot;sample&quot;<br>  api_key: &quot;98785549878945&quot;<br>  api_secret: &quot;3s258d44f1s2a22g22d23a3s3d22a3d2&quot;<br><br>production:<br>  cloud_name: &quot;sample&quot;<br>  api_key: &quot;98785549878945&quot;<br>  api_secret: &quot;3s258d44f1s2a22g22d23a3s3d22a3d2&quot;</pre><p>you can find your api_key and api_secret on your cloudinary dashboard. The next thing todo is generate carrierwave uploader.</p><pre>rails g uploader avatar</pre><p>in avatar_uploader.rb comment out the storage and store_dir lines since we are going to use Cloudinary.</p><pre># app/uploaders/avatar_uploader.rb</pre><pre>class AvatarUploader &lt; CarrierWave::Uploader::Base<br> # Include RMagick or MiniMagick support:<br> # include CarrierWave::RMagick<br> # include CarrierWave::MiniMagick<br> <strong>include Cloudinary::CarrierWave</strong><br> # Choose what kind of storage to use for this uploader:<br> #storage :file<br> # storage :fog# Override the directory where uploaded files will be stored.<br> # This is a sensible default for uploaders that are meant to be mounted:<br> # def store_dir<br> # “uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}”<br> # end</pre><h3>CarrierWave setting</h3><p>Generate migration for avatar and add it to our model or create it when you were creating User model</p><pre>rails g migration AddAvatarToUser avatar:string<br>rake db:migrate</pre><p>Now add this to our model so that rails recognize the uploader</p><pre># app/models/user.rb<br>mount_uploader :avatar, AvatarUploader</pre><p>and finally add this code to our controller,</p><pre>#apps/controller/users_controller.rb</pre><pre>def create<br> <a href="http://twitter.com/post">@</a>user = User.new(user_params)<br>   if <a href="http://twitter.com/post">@</a>user.save<br>      render json: { result: true, msg: &#39; The image is sucessfully         uploaded!!&#39;}, status: :created<br>   else<br>      render json: {result: false, user: <a href="http://twitter.com/post">@</a>user.errors }, status:          :unprocessable_entity<br>   end<br> end</pre><p>and your private method:</p><pre>private<br>def user_params<br> params.permit(:name, :avatar)<br>end</pre><p>The content of users_controller.rb is just an example, you can modify it as you want to suits your needs.</p><h3>Upload test with Postman</h3><p>Postman is an awesome tools for testing API, I assume that you are familiar with it. bellow image is how I send POST request for uploading image</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cF54PbMVe11_hnF-1tNi0w.png" /><figcaption>This is how I send POST request to the rails app</figcaption></figure><p>If we try to send the path name, carrierwave will throw an exception :<br><em>CarrierWave::FormNotMultipart (You tried to assign a String or a Pathname to an uploader, for security reasons, this is not allowed. If this is a file upload, please check that your upload form is multipart encoded.)</em> in another word, we can not assign <em>avatar</em> value with image path or strings.</p><p>After we successfully upload the image, avatar collumn will contain an url to our image at the Cloudinary server.</p><p>That’s it, now we can upload file to Cloudinary</p><p>you can learn more about this at Cloudinary Documentation at <a href="https://cloudinary.com/documentation/rails_carrierwave">https://cloudinary.com/documentation/rails_carrierwave</a></p><p>and next time I will cover about transformation and resizing image using Cloudinary gem</p><p>Cheers, and have a nice day…</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ecfee7c5b973" width="1" height="1" alt=""><hr><p><a href="https://medium.com/binar-academy/carrierwave-and-cloudinary-for-uploading-images-in-rails-api-ecfee7c5b973">Carrierwave and Cloudinary for uploading images in Rails API</a> was originally published in <a href="https://medium.com/binar-academy">Binar Academy</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>