<?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 Nattaphol Srisa on Medium]]></title>
        <description><![CDATA[Stories by Nattaphol Srisa on Medium]]></description>
        <link>https://medium.com/@natpalmsl?source=rss-c780cc49e941------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*3PCbGus81RO0vnlW.</url>
            <title>Stories by Nattaphol Srisa on Medium</title>
            <link>https://medium.com/@natpalmsl?source=rss-c780cc49e941------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 05 Dec 2026 18:35:03 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@natpalmsl/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[What is a Black Hole?]]></title>
            <link>https://medium.com/swlh/what-is-black-holes-977d89d88907?source=rss-c780cc49e941------2</link>
            <guid isPermaLink="false">https://medium.com/p/977d89d88907</guid>
            <category><![CDATA[black-holes]]></category>
            <category><![CDATA[space]]></category>
            <category><![CDATA[singularity]]></category>
            <category><![CDATA[event-horizon]]></category>
            <dc:creator><![CDATA[Nattaphol Srisa]]></dc:creator>
            <pubDate>Sat, 23 May 2020 10:05:05 GMT</pubDate>
            <atom:updated>2020-05-25T22:58:28.122Z</atom:updated>
            <cc:license>http://creativecommons.org/publicdomain/zero/1.0/</cc:license>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*U9nNRilH0bBArtYP.jpg" /><figcaption><a href="https://www.nasa.gov/sites/default/files/cygx1_ill.jpg">https://www.nasa.gov/sites/default/files/cygx1_ill.jpg</a></figcaption></figure><h3>Black (Invisible) Holes</h3><p>Don’t let its name fool you, a black hole is not actually black. A black hole is <strong>a region in space where the pulling force of gravity is so strong that nothing can escape</strong> even the fastest object in the universe — light. Since no light can escape, black holes are considered <strong>invisible</strong>. We can’t see black holes but we have several ways to located it using its properties. We will talk about it later in this article.</p><p>A black hole is a very special space object that scientists has been trying to solve its identity for centuries. The first modern solution of general relativity that would characterize a black hole was found by Karl Schwarzschild in 1916, although its interpretation as a region of space from which nothing can escape was first published by David Finkelstein in 1958.</p><h3>How black holes are created?</h3><p>A black hole is what remains when a massive star dies. A star that has more than <strong>3 times mass of our Sun</strong> can create a black hole.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/488/1*aAUqL4jpKKY_oEUKJqOLoA.png" /><figcaption>Our Sum comparing to other enormous stars in the universe</figcaption></figure><p>Stars are hydrogen atoms that collapse from the enormous gas cloud under their own gravity.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*jCaqdeVNKMRaaKb2Ty4XEw.png" /></figure><p>In its core, <strong>nuclear fusion crushed hydrogen atoms into helium</strong>. This creates <strong>heat</strong> and <strong>radiation</strong> that push against the gravity. The amount of emitted heat and radiation is huge enough to not let the star collapse into itself by its own gravity. A star need to balance both of these forces in order to survive.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Rx-vOhQorh1ZArT1RVoaNg.png" /></figure><p>The heat and pressure at the core can fuse helium into <strong>carbon. </strong>If the star is massive enough, it can fuse carbon into heavier elements such as oxygen, neon, silicon, magnesium, sulfur and <strong>iron</strong>.</p><p>The problem is that <strong>iron cannot burn</strong>. This means no radiation and heat will be generated. Without the pushing force from the inside of the star, the balance is broken and the star collapsed by its own gravity.</p><p>In a fraction of a second, due to its massive gravitational force, the core becomes so tightly packed that protons and electrons merged to form neutrons. The core heats to billions of degrees and explodes in to a <strong>supernova</strong>. The remains of the core can form a<strong> neutron star</strong> or a <strong>black hole</strong> depending upon the mass of the original star.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/750/0*zGFLBzg3cHorDTi7.jpg" /></figure><h3>How big are black holes?</h3><h4>Primordial (Miniature)</h4><p>It is the smallest type of black holes. Its size can be as small as a <strong>single atom</strong> but with the mass of a large mountain.</p><h4><strong>Stellar</strong></h4><p>Stellar is the most common type of medium-sized black holes. The mass of a stellar black hole can be up to 20 times greater than the mass of the sun. It can fit inside a ball with a diameter about 10 miles.</p><h4>Intermediate</h4><p>Black holes that are larger than Stellar but smaller than Supermassive black holes</p><h4>Supermassive</h4><p>This type of black holes is the largest black holes that has ever existed. Its mass could be greater than 1 million Suns combined. The diameter is about the size of our Solar System. It is suspected that every large galaxy contains a supermassive black hole at its center.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*O3csMOTXnYKlVPSu.jpg" /><figcaption><a href="https://www.nasa.gov/jpl/nustar/pia18842">Mass Chart for Dead Stars and Black Holes</a></figcaption></figure><h3>The types of black holes</h3><p>There are 2 main types of black holes, non-rotating and rotating black holes.</p><h3>Schwarzschild (Non-rotating black hole)</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*GBR_VW1XXGWFciMV.jpg" /><figcaption><a href="https://www.youtube.com/watch?v=Q7E-KA-MYjc">Schwarzchild radius</a></figcaption></figure><p>This is the simplest type of black holes. This type of black hole only has <strong>singularity</strong> and <strong>event horizon</strong>. Don’t worry about those terms if you haven’t known it before I will describe it later. The Schwarzschild radius is the size of the event horizon of a non-rotating black hole.</p><h3>Kerr (Rotating black hole)</h3><p>This type of black holes is more interesting. Its ability to rotate has create an interesting components that allow us to study and understand the underlying knowledge of black holes and helps us to be able to discover them easier.</p><p>The components of Kerr or a rotating black hole are:</p><ul><li>Singularity</li><li>Event horizon</li><li>Photon sphere</li><li>Relativistic jets</li><li>Innermost stable circular orbit (ISCO)</li><li>Accretion disc</li><li>Ergosphere</li><li>Static limit</li></ul><p>The following image is a well illustration of a rotating black hole, so I will borrow some of its explanation.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*1_CGs_JOGPsWc2xA" /><figcaption>This artist’s impression depicts a rapidly rotating supermassive black hole surrounded by an accretion disc. This thin disc of rotating material consists of the leftovers of a Sun-like star which was ripped apart by the tidal forces of the black hole. Shocks in the colliding debris as well as heat generated in accretion led to a burst of light, resembling a supernova explosion. Credit: ESO, ESA/Hubble, M. Kornmesser/N. Bartmann</figcaption></figure><h4>Singularity</h4><p>Singularity is located at the center. It is where all the mass of the star is concentrated into a region of <strong>infinite density</strong>. All the matter and energy that fall into the black hole ends up here. The prediction of infinite density by general relativity is thought to indicate the breakdown of the theory where quantum effects become important.</p><h4>Event horizon</h4><p>This is the <strong>black part</strong> of the black hole. It is a huge radius around the singularity where matter and energy cannot escape the black hole gravity. It is the point of no return.</p><p>You can think of the spacetime as a super <strong>elastic sheet</strong> which will not tear down even you put something super heavy on it. When you put a ball(mass) onto the sheet. The region around the ball will be sank down. The black hole is a super tiny ball with a mass of an earth. When you put this tiny ball onto the sheet. A small area around the sheet sank down and create an extremely steep hole.</p><p>The ball is <strong>singularity</strong> and the area that sank down is the <strong>event horizon</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*RZxSyf2qmeg8fG7_hlvsXw.png" /><figcaption>The illustration of a normal mass and a black hole when put onto an elastic sheet</figcaption></figure><h4>Photon sphere</h4><p>Photons are emitted from nearby hot plasma in jets or an accretion disc. Without gravity, it would travel in straight line, but just outside the event horizon of the black hole, the gravity is strong enough to <strong>bend</strong> their path so that it can be seen as a bright ring surrounding black hole.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/465/1*QTMFCGqbwlMn8oRzYv1eWQ.png" /></figure><h4>Relativistic jets</h4><p>Gas, dust remained from stars falling into the black hole produce jets of particles and radiation blasting out from the black hole’s poles at near light speed. They can extend for thousands of light-years into space.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*tKlCSwlM3-Vp7oZQ.jpg" /><figcaption><a href="https://en.wikipedia.org/wiki/Elliptical_galaxy_M87">Elliptical galaxy M87</a> emitting a relativistic jet, as seen by the <a href="https://en.wikipedia.org/wiki/Hubble_Space_Telescope">Hubble Space Telescope</a></figcaption></figure><h4>Innermost stable circular orbit (ISCO)</h4><p>The last place that material can orbit safely without the risk of falling past the point of no return. It plays an important role in black hole <strong>accretion disks</strong> since it marks the <strong>inner edge</strong> of the disk. The ISCO radius is different depending on the type of a black hole (rotating or non-rotating).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/628/0*SFL_dbgJ3Oz7x4Hj.png" /><figcaption><a href="https://www.researchgate.net/figure/The-locations-of-the-innermost-stable-circular-orbits-ISCO-and-the-innermost-circular_fig4_266204198">The locations of the innermost stable circular orbits (ISCO) and the innermost circular orbits (ICO) on the equatorial plane are schematically shown. The left and right panels show the Schwarzschild black hole and a nearly maximally rotating Kerr black hole, respectively.</a></figcaption></figure><h4>Accretion disc</h4><p>A disc of <strong>superheated gas and dust whirls around a black hole</strong> at immense speeds, producing electromagnetic radiation (X-rays, optical, infared and radio) that reveal the black hole’s location. Some of this material is doomed to cross the event horizon, while other parts may be forced out to create jets.</p><p>In the recently news that we captured the image of a black hole, what we see is actually the image of accretion disk not the black hole itself.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*T3YrN2W2YWNOfw0E.jpg" /><figcaption><a href="https://www.slashgear.com/new-black-hole-study-proves-a-40-year-old-theory-09616115/">The accretion disk is the gas and dust that whirls around a black hole</a></figcaption></figure><h4>Ergosphere</h4><p>Ergosphere is an en egg-shaped region of <strong>distorted space</strong> around the event horizon. The distortion is caused by the spinning of the black hole which drags the space around it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/320/0*OcQzyLg4JYnuhVjh.gif" /><figcaption><a href="https://en.wikipedia.org/wiki/Black_hole#/media/File:BlackHole_Lensing.gif">Simulation of gravitational lensing by a black hole, which distorts the image of a galaxy in the background</a></figcaption></figure><h4>Static limit</h4><p>The boundary between the ergosphere and normal space.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/326/1*H_JN1sTC4GJ4iOQCY9tJTg.png" /></figure><h3>How do we detect black hole?</h3><p>Although we cannot see black holes due to its invisibility, we can detect or guess the presence of one by measuring its effects on objects around it. The following effects may be used:</p><ul><li>Mass estimates from objects orbiting a black hole or spiralling into the core</li><li>Gravitational lens effects</li><li>Emitted radiation</li></ul><h4><strong>Behavior</strong> of orbital objects</h4><p>By looking at the behavior of the objects, you can detect the presence of a black hole. You then use measurements of the movement of objects around a suspected black hole to calculate the black hole’s mass.</p><p>For example, if a visible star or disk of gas has a <strong>wobbling motion</strong> or spinning and there is not a visible reason for this motion. The invisible reason has an effect that appears to be caused by an object with a greater than three solar masses (too big to be a neutron star). Then a black hole may be causing the motion.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/674/1*M_GPwH0n58v7GxE6F9cPqQ.png" /><figcaption>An example of motions of objects rotating around a mass.</figcaption></figure><h4>Gravitational lens effects</h4><p>As mentioned in the <strong>ergosphere</strong> part, it creates a gravitational lens effect that can be used to detect the black hole.</p><p>Einstein’s General Theory of Relativity predicted that <strong>gravity could bend space. </strong>This was later confirmed during a solar eclipse when a star’s position was measured <strong>before, during and after the eclipse</strong>. The star’s position shifted because the light from the star was bent by the sun’s gravity.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/320/0*OcQzyLg4JYnuhVjh.gif" /><figcaption><a href="https://en.wikipedia.org/wiki/Black_hole#/media/File:BlackHole_Lensing.gif">Simulation of gravitational lensing by a black hole, which distorts the image of a galaxy in the background</a></figcaption></figure><p>Therefore, an object with immense gravity (like a galaxy or black hole) between the Earth and a distant object could bend the light from the distant object into a focus, much like a lens can.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/285/1*-mzVIDwBTPrh0hLaYR1Mow.png" /><figcaption>In the above image, the brightening of MACHO-96-BL5 happened when a <strong>gravitational lens</strong> passed between it and the Earth. When the<a href="https://science.howstuffworks.com/hubble.htm"> Hubble Space Telescope</a> looked at the object, it saw two images of the object close together, which indicated a gravitational lens effect. The intervening object was unseen. Therefore, it was concluded that a black hole had passed between Earth and the object.</figcaption></figure><h4>Emitted radiation</h4><p>When material falls into a black hole from a companion star, it gets heated to millions of degrees Kelvin and accelerated. The superheated materials <strong>emit X-rays </strong>which can be detected by X-ray telescopes such as the orbiting Chandra X-ray Observatory.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/660/1*2d2DUJHBM8O1_OnDcP0HWA.png" /></figure><p>In addition to X-rays, black holes can also eject materials at high speeds to form <strong>jets. </strong>Many galaxies have been observed with such jets. Currently, it is thought that these galaxies have supermassive black holes at their centers that produce the jets as well as strong radio emissions</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/285/0*xXUVosCkIbhOF-rS.jpg" /><figcaption><a href="https://science.howstuffworks.com/dictionary/astronomy-terms/black-hole.htm">The images on the left and bottom are ground-based radiotelescope images of the heart of galaxy M87. The image on the right is a visible image from the Hubble Space Telescope. Note the jet of material coming from M87.</a></figcaption></figure><h3>Capturing the first image of a black hole</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/0*MblCxUBIBdpMlFYW.jpg" /><figcaption><a href="https://en.wikipedia.org/wiki/Black_hole#/media/File:Black_hole_-_Messier_87_crop_max_res.jpg">The supermassive black hole at the core of supergiant elliptical galaxy Messier 87, with a mass ~7 billion times the Sun’s, as depicted in the first image released by the Event Horizon Telescope (10 April 2019). Visible are the crescent-shaped emission ring and central shadow, which are gravitationally magnified views of the black hole’s photon ring and the photon capture zone of its event horizon. The crescent shape arises from the black hole’s rotation and relativistic beaming; the shadow is about 2.6 times the diameter of the event horizon.</a></figcaption></figure><p>Capturing a picture of a black hole is not an easy task. Imagine standing on the 50th floor of the building trying to take a picture of an ant on the street with 2000s phone camera in a rainstorm day. It is the same situation when trying to take a picture of a black hole. The galaxy M87 is the <strong>too far. </strong>A <strong>lot of stars and dust</strong> through the way. We need a lens <strong>as large as the earth</strong> to capture it with a good resolution.</p><h4>Why choose Messier 87 (M87)?</h4><p>The closest black hole we could possibly take a picture is Sagittarius A* (Milky Way), but it was too small. The reasons they choose M87 is that it is nearby, very large, has an accretion disk traveling at near relativistic speeds and has an intense gravity, with predicted mass of 6.5 billion solar masses. This makes for a very photogenic black hole, surrounded by radiant heat, and offering an opportunity to show the shadow of the black hole<strong> </strong>in the center.</p><h4>How do they create the earth-sized telescope?</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/730/1*6WeFOd_DI1z_3EhX8PPF7w.png" /></figure><p><strong>Event Horizon Telescope Project </strong>create an earth size telescope by combining 11 telescopes from all over the world (in 2018). They used <strong>Interferometry </strong>technique to capture the images</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2Ft5cSBmGkW3E%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3Dt5cSBmGkW3E&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2Ft5cSBmGkW3E%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/db855e95371b83596601c9cddfee87f7/href">https://medium.com/media/db855e95371b83596601c9cddfee87f7/href</a></iframe><p>Taking a picture of a black hole is like trying to listen to the playing piano with no sound. Turning on one key, we won’t be able to capture the song. Turning on <strong>5–6 keys</strong>, we can guess what the song is. Think of it as a game show where you are trying to guess what is picture is, so the MC randomly flip a part of an image one by one until you can guess what it is.</p><h4>Handling with a huge amount of data</h4><p>The combined amount of data is over 5,242,880 Gigabytes. Sending huge amount of data via undersea internet cable may crash the whole internet system. Moreover, some of the research lab was located in a really far area which has no connection to the cable. To solve this, they exported the data to hard disks and manually carried it over the the planes.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/720/1*ntvceIIRFFEnQoHvP8jwqQ.png" /><figcaption>MIT computer scientist Katie Bouman with stacks of hard drives of black hole image data.</figcaption></figure><h4>Processing Data</h4><p>Katie Bouman creates <strong>CHIRP (Continuous High-resolution Image Reconstruction using Patch priors) </strong>algorithm. It is the algorithm that transform low resolution image into high resolution image. It combine images taken from the every telescopes, and turn it into a cohesive image.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1001/1*FZnsiTQu220znbNauk-VKA.png" /></figure><h4>What have we got from the black hole image?</h4><ul><li>Accretion Disk is surrounding the black hole</li><li>It takes 2 days to circulate 1 period</li><li>Found Relativistic Beaming theory to explain how accretion disk shaped like a donut due to black hole gravity</li><li>Quantum mechanic can be further to develop</li><li>Prove the General Relativity of Einstein</li></ul><p>This article is written for an assignment of the course <strong>Science Technology and Modern World</strong> at King Mongkut’s Institute of Technology (KMITL), Thailand.</p><p>The article is used for educational purposes only.</p><h4>References</h4><ul><li><a href="https://www.nasa.gov/audience/forstudents/5-8/features/nasa-knows/what-is-a-black-hole-58.html">https://www.nasa.gov/audience/forstudents/5-8/features/nasa-knows/what-is-a-black-hole-58.html</a></li><li><a href="https://www.youtube.com/watch?v=e-P5IFTqB98">https://www.youtube.com/watch?v=e-P5IFTqB98</a></li><li><a href="https://science.howstuffworks.com/dictionary/astronomy-terms/black-hole.htm">https://science.howstuffworks.com/dictionary/astronomy-terms/black-hole.htm</a></li><li><a href="https://science.nasa.gov/astrophysics/focus-areas/black-holes">https://science.nasa.gov/astrophysics/focus-areas/black-holes</a></li><li><a href="https://www.daviddarling.info/encyclopedia/K/Kerr_black_hole.html">https://www.daviddarling.info/encyclopedia/K/Kerr_black_hole.html</a></li><li><a href="https://ritholtz.com/2019/04/singularity/">https://ritholtz.com/2019/04/singularity/</a></li><li><a href="https://en.wikipedia.org/wiki/Karl_Schwarzschild">https://en.wikipedia.org/wiki/Karl_Schwarzschild</a></li><li><a href="https://www.researchgate.net/figure/The-locations-of-the-innermost-stable-circular-orbits-ISCO-and-the-innermost-circular_fig4_266204198">https://www.researchgate.net/figure/The-locations-of-the-innermost-stable-circular-orbits-ISCO-and-the-innermost-circular_fig4_266204198</a></li><li><a href="https://www.quora.com/Why-was-M87-s-supermassive-black-hole-chosen-to-be-photographed-over-all-other-visible-black-holes">https://www.quora.com/Why-was-M87-s-supermassive-black-hole-chosen-to-be-photographed-over-all-other-visible-black-holes</a></li><li><a href="https://spaceth.co/the-first-black-hole-pic/">https://spaceth.co/the-first-black-hole-pic/</a></li><li><a href="https://thematter.co/science-tech/why-first-black-hole-pic-matters/75097">https://thematter.co/science-tech/why-first-black-hole-pic-matters/75097</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=977d89d88907" width="1" height="1" alt=""><hr><p><a href="https://medium.com/swlh/what-is-black-holes-977d89d88907">What is a Black Hole?</a> was originally published in <a href="https://medium.com/swlh">The Startup</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[An Introduction to Quantum Computer]]></title>
            <link>https://medium.com/discourse/an-introduction-to-quantum-computer-87337a1ca22?source=rss-c780cc49e941------2</link>
            <guid isPermaLink="false">https://medium.com/p/87337a1ca22</guid>
            <category><![CDATA[technology]]></category>
            <category><![CDATA[superposition]]></category>
            <category><![CDATA[science]]></category>
            <category><![CDATA[quantum-computer]]></category>
            <category><![CDATA[quantum]]></category>
            <dc:creator><![CDATA[Nattaphol Srisa]]></dc:creator>
            <pubDate>Thu, 21 May 2020 17:08:29 GMT</pubDate>
            <atom:updated>2020-05-26T02:08:37.734Z</atom:updated>
            <cc:license>http://creativecommons.org/publicdomain/zero/1.0/</cc:license>
            <content:encoded><![CDATA[<h3>Journey to Quantum Computer</h3><p>Since the 1900s when the very first computer was built. It was getting smaller and more powerful year by year really fast. From the size bigger than humans to be <a href="https://www.theverge.com/circuitbreaker/2018/3/19/17140116/ibm-worlds-smallest-computer-grain-of-salt-solar-powered">smaller than a grain of salt</a> and approaching to an atom. Unfortunately, we are reaching the end of the road, the physical limit.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/597/0*wvzvs-a38hCbM6ZA.jpg" /><figcaption><a href="https://www.theverge.com/circuitbreaker/2018/3/19/17140116/ibm-worlds-smallest-computer-grain-of-salt-solar-powered">IBM unveiled the ‘world’s smallest computer’</a></figcaption></figure><h4>How does the computer work?</h4><p>The problem lies down deep inside the way a computer works. The computer is nothing but a bunch of <strong>circuit chips</strong> combined and working together. The circuit chip contains <strong>basic modules</strong> that do simple tasks like addition. The basic module is the combination of <strong>logic gates</strong> (AND, OR, NOT) if you can still remember from your digital circuit class. Logic gates are built from <strong>transistors</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*IJOMKcmlf3eyCacz" /><figcaption><a href="https://www.youtube.com/watch?v=JhHMJCUmq28&amp;t=1s">Computer components break down</a></figcaption></figure><p>A transistor is simply the gate or switch that can either block or let electricity pass through. The flow of electricity here is the tiniest representation of <strong>information</strong> in a computer system. This tiny information is called “<strong>Bits</strong>”. Bits can be 0 or 1. The combination of bits is used to represent more complex information like ASCII characters.</p><p>Computers nowadays are getting smaller and more powerful by making those transistors be smaller so it can be packed more into a CPU.</p><h4>The problem of small things (too small)</h4><p>Remember that transistors are just a gate that blocks electricity. Electricity is basically a moving flow of <strong>electrons.</strong> Here is the problem. The gates(transistors) nowadays are so small that it approaching the size of a few atoms. Typical transistors have a size of 14nm while a single atom is around 0.1 o 0.5 nm. With this small size, <strong>electrons can just transfer themselves to the other side of the gate! </strong>It can be done via the process called <a href="https://www.youtube.com/watch?v=WPZLRtyvEqo">“<strong><em>Quantum Tunneling</em></strong>”</a>. We are reaching the physical barrier of our technological progress. Even Gandalf cannot help anymore 😂.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/512/0*h15Gd0bEE7Snsdo0" /></figure><h4>Here comes the quantum</h4><p>Since it is impossible for computers to shrink anymore, scientists try to take advantage of the quantum properties by building <strong>a Quantum computer</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/585/0*YrAheXf4VC0ypRH6.png" /><figcaption><a href="https://www.google.com/url?sa=i&amp;url=https%3A%2F%2Fwww.notebookcheck.net%2FIBM-presents-new-quantum-computer-with-53-Qubit-CPU.435024.0.html&amp;psig=AOvVaw3regsL8Ups06MtRv3DGuiA&amp;ust=1589566652406000&amp;source=images&amp;cd=vfe&amp;ved=0CAIQjRxqFwoTCJj4-bP7s-kCFQAAAAAdAAAAABAJ">IBM Quantum Computer</a></figcaption></figure><h3>The Quantum Computer</h3><p>A Quantum computer is a kind of computer that utilizes quantum properties. It is so fast that it can massively outperform even the most powerful supercomputer nowadays. Quantum properties are <strong>Superposition</strong> and <strong>Entanglement. </strong>I can’t get so deep into the fundamentals of how these properties really work, so I will try to simplify it so you can grasp the underlying concept of them.</p><h3>Superposition</h3><p>In a traditional computer, we have a representation of data called “Bits”. In a quantum computer, we also have a similar representation. It is called “<strong>Qubits</strong>”. Qubits have a weird property. It can be 0 and 1 at the same time. This state is called <strong>superposition</strong>. I would like to suggest you watch <a href="https://www.youtube.com/watch?v=VwWRX9IdblE">this video</a> if you really want to understand what superposition really is and where does it come from.</p><p>Bits in a traditional computer can be measured by looking at the existence of electrons (electricity). For qubits, there are a number of physical objects that can be used such as a photon, a nucleus, and an electron.</p><p>All electrons have their own magnetic field, so it is basically a tiny bar of a magnet. This property is called <strong>spin</strong>. If you place it in the magnetic field, the electron will align itself with that field. This is the lowest energy state of electron or <strong>spins down</strong>. If you would like to move the electron to be the opposite of that field, you will need to push force to make it spins. This is the highest energy state or <strong>spins up</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*YPNGIuQt8hn_PG2N.jpg" /><figcaption><a href="https://www.google.com/url?sa=i&amp;url=https%3A%2F%2Fwww.vasantcorporation.com%2Fspin_pauli_exclusion_compensated.php&amp;psig=AOvVaw09Bt2J8cBlVHtNVlhIBH7q&amp;ust=1590157814055000&amp;source=images&amp;cd=vfe&amp;ved=0CAIQjRxqFwoTCKj0oNGVxekCFQAAAAAdAAAAABAD">The image illustrates how an electron is spin up and spin down.</a></figcaption></figure><p>Now, we might think that it looks like a classical bit where it has 2 states. We can use spin up as 0 and spin down as 1. However, a qubit can be in both states at once before you measure it as stated in the superposition property. When you measured it, this superposition state will be collapsed and it must choose whether it will be “up” or “down”. This state can be defined by 2 coefficients indicating the <strong>relative probability</strong> of finding the electron in one state or another.</p><p>The concept of superposition is quite difficult to understand so it is usually explained and illustrated using Thomas Young’s <a href="https://www.youtube.com/watch?v=p-MNSLsjjdo">double-slit experiment</a>. In short, superposition is the ability of a qubit in the quantum system to be in multiple states at the same time until it is measured.</p><h3>Entanglement</h3><p>Entanglement is another super weird qubit’s property. A qubit can be entangled with another qubit. With this connection, it makes each of the qubits react to a change in other’s state instantaneously no matter how far they are apart. When measuring one qubit, you can directly deduce the properties of its partner without having to look.</p><p>For example, we have 2 electrons that are entangled together. As I have mentioned earlier that electrons have a property called <strong>spin </strong>and it can be either <strong>spin up </strong>or <strong>spin down</strong>. If we measured the first electron and the result is spin up, another electron will always be spin down when we measure it later. It is true even we separate them apart from the opposite side of the universe as long as it does not interact with other things.</p><p>If you would like to understand the underlying idea, I suggest you watch <a href="https://www.youtube.com/watch?v=JFozGfxmi8A">this video</a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/0*qaZAvjaZ9nchQu0p.jpg" /><figcaption><a href="https://www.google.com/url?sa=i&amp;url=https%3A%2F%2Fwww.hpcwire.com%2F2020%2F02%2F20%2Fchina-researchers-set-distance-record-in-quantum-memory-entanglement%2F&amp;psig=AOvVaw3itNIjww1rKjIN9q8NAP9L&amp;ust=1590162008948000&amp;source=images&amp;cd=vfe&amp;ved=0CAIQjRxqFwoTCNDu16WlxekCFQAAAAAdAAAAABAV">Quantum entanglement illustration</a></figcaption></figure><h3>How does it faster than a classical computer?</h3><p>Now, I hope you get an idea of quantum properties, but you might wonder why those properties make a quantum computer a lot faster than a classical computer. The following is the <strong>overly simplified</strong> explanation of how it works.</p><p>Imagine you would like to<strong> find a factor of a number N</strong> in a classical computer. The simplest way is to start from the lowest number like 2 and check if 2 is a factor of N. Then you increase the value by 1 at a time and measure again and again until you reach the number N-1 and stop. This requires approximately <strong>N steps </strong>in order to find a factor of N.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*NnpSORRaV04TH-pGSQjv9w.png" /><figcaption>Finding a factor of N in a classical computer</figcaption></figure><p>However, it is so much different is a quantum system. As qubit’s superposition and entanglement, you can have multiple states of qubits representation at once if you have enough qubits. The possible maximum steps that you are required to find a factor of the number N is maybe only 2 steps!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*mJrg3XOUhwa7hi_uAUZ0yQ.png" /><figcaption>Finding a factor of N in a quantum computer</figcaption></figure><p>The classical bits can represent 0 or 1 at a time, while the quantum bits can be both 0 and 1. If you have <strong><em>n</em></strong> classical bits, you can have 2<em>ⁿ</em> representation of numbers but you can only have one of those representations at a time. In a quantum system, if you have <strong><em>n</em></strong> qubits, you can have <strong>2<em>ⁿ</em> representation at a time</strong>!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*U_K_CI7r6N-NVKkJgRgRyQ.png" /><figcaption><a href="https://www.youtube.com/watch?v=JhHMJCUmq28&amp;t=250s">Illustration of qubits vs bits</a></figcaption></figure><h3>The use of quantum computers</h3><h4>Database Searching</h4><p>A normal computer might need to perform comparison N times to query something out from a database of N records, while a quantum computer may use only a square root of N times to query the same thing. It might not seem different in a small database, but for a super large database it is a game-changer.</p><h4>IT Security</h4><p>Right now our precious data like passwords and other confidential information are kept secure by an encryption system. This encryption system works by using a public and private key. We give our public key to others to encrypt the message that can only be decrypted by our own private key. This public key can be used to calculate our secret private key, but it takes years to find it using normal computers even the fastest computer in the world. With the unusual speed of a quantum computer, <strong>it could take only seconds or minutes to perform math and discover our private key</strong>!</p><h4><strong>Simulations</strong></h4><p>In order to simulate quantum worlds or molecules, it consumes intensively huge resources and often lack accuracy. Why should not we simulate quantum physics with the actual quantum system? If we could accurately simulate molecules or quantum environments, we could possibly discover lots of new facts or theories that we could not even think to try it on these days.</p><h3>How far have we come?</h3><p>You might have heard about <a href="https://www.bbc.com/news/science-environment-50154993">Google claims Quantum Supremacy recently in late 2019</a>. The name of the protagonist is called <strong>the Sycamore chip</strong>. The Sycamore chip contains 54 qubits. According to Google, <strong>this chip can perform the task that requires 10,000 years to complete using the most powerful supercomputer in only 3 minutes 20 seconds! </strong>This was astonishing! Here is <a href="https://www.youtube.com/watch?v=-ZNEzzDcllU">the video</a> of Google demonstrating their Quantum Supremacy.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*lLVQJxpW-H_OoBKe32fnCA.png" /><figcaption>Google’s Sycamore chip</figcaption></figure><p>This article is written for an assignment of the course <strong>Science Technology and Modern World</strong> at King Mongkut’s Institute of Technology (KMITL), Thailand.</p><p>The article is used for educational purposes only.</p><h4>References</h4><ul><li><a href="https://youtu.be/JhHMJCUmq28">Quantum Computers Explained — Limits of Human Technology</a></li><li><a href="https://www.youtube.com/watch?v=-ZNEzzDcllU">Quantum Supremacy from Google</a></li><li><a href="https://www.youtube.com/watch?v=g_IaVepNDT4">How Does a Quantum Computer Work</a></li><li><a href="https://www.youtube.com/watch?v=zNzzGgr2mhk">How To Make a Quantum Bit</a></li><li><a href="https://www.youtube.com/watch?v=wUwZZaI5u0c&amp;t=56s">Hacking at Quantum Speed with Shor’s Algorithm</a></li><li><a href="https://www.youtube.com/watch?v=VwWRX9IdblE">Superposition of Quantum States</a></li><li><a href="https://www.youtube.com/watch?v=JFozGfxmi8A">Quantum Entanglement: Spooky Action at a Distance</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=87337a1ca22" width="1" height="1" alt=""><hr><p><a href="https://medium.com/discourse/an-introduction-to-quantum-computer-87337a1ca22">An Introduction to Quantum Computer</a> was originally published in <a href="https://medium.com/discourse">Dialogue &amp; Discourse</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Introduction to Disciplined Agile Delivery]]></title>
            <link>https://medium.com/@natpalmsl/introduction-to-disciplined-agile-delivery-190e29ca283f?source=rss-c780cc49e941------2</link>
            <guid isPermaLink="false">https://medium.com/p/190e29ca283f</guid>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[agile]]></category>
            <category><![CDATA[disciplined-agile]]></category>
            <dc:creator><![CDATA[Nattaphol Srisa]]></dc:creator>
            <pubDate>Thu, 16 Apr 2020 17:44:14 GMT</pubDate>
            <atom:updated>2020-04-16T17:44:14.596Z</atom:updated>
            <cc:license>http://creativecommons.org/publicdomain/zero/1.0/</cc:license>
            <content:encoded><![CDATA[<h3><strong>What is Disciplined Agile Delivery?</strong></h3><p>Disciplined Agile Delivery is a learning-oriented, people-first hybrid approach to IT solution delivery. DAD is goal-driven and can scalable with the risk-value delivery lifecycle.</p><p>The framework of DAD gives a simplified process to make a decision around the incremental and iterative solution delivery. Using DAD streamlines in the IT work is quite good because it allows for great scaling. DAD has been adapted to other strategies such as Scrum, Agile modeling, Unified Process, and Kanban, to create a hybrid delivery system with relevant parts from each technique.</p><p>Disciplined Agile Delivery is the goal-driven approach, meaning that DAD is more flexible and accessible to scale the work than the other agile method. From the beginning, DAD offers choices that lead to the end goal and also includes the other possible options to consider, before making a final decision. The goal of DAD consists of four main sections: the inception phase, construction phase, transition phase, and the ongoing goals. The inception phase focuses on identifying the end goal, putting people into a team and developing a strategy while securing funding and identifying risks. The construction phase consists of addressing the shareholder’s needs and working closer to reach the end goals. The transition phase is to check that the solution is ready to be deployed and implement it. The ongoing goals should be focused on growing the team, completing the project task, continue to address risk, and have constant improvement. DAD lifecycle addresses the entire project from pre-production to post-production, unlike primary agile methods.</p><p>Disciplined Agile Delivery is people-driven, so the team aspect of DAD is essential. The role division must be clear in order to have the success of using DAD. The primary of the DAD framework consists of five significant roles, these roles will always be in a DAD framework in any scale of mission, these roles are the stakeholder, product owner, team leader, team member, and the architecture owner. The secondary roles are domain expert, technical expert, tester, integrator and any number of specialists. Sometimes, these secondary team members have been using temporarily to address an issue in scaling. So these teams work together and with the clients to ensure that the product is exactly as it should be. DAD also allows teams to share their discoveries with the other teams.</p><p>Disciplined Agile Delivery promotes a risk-value lifecycle, The riskier work is done at the beginning of the project to increase the chances of success. But this can also lead to failure in the earlier so the team has more time to come up with the solution. DAD teams are able to see their goals together and reach their goal as a team, instead of individual goals that may not lead to final success. DAD is a good development approach to solution delivery that is adapted to each project.</p><h3><strong>How does it work and How to apply it</strong></h3><p>Now what we know what DAD is let’s see how it works and how to apply it. Firstly we will analyze the definition of DAD given by IBM and also stated above:</p><blockquote><strong><em>“The Disciplined Agile Delivery (DAD) process framework is a people-first, learning-oriented hybrid agile approach to IT solution delivery. It has a risk-value life cycle, is goal-driven, and is enterprise aware”.</em></strong></blockquote><p>From this definition we can extract key ideas of DAD which are the following:</p><ul><li>People first</li><li>Learning-oriented</li><li>Agile</li><li>Hybrid</li><li>IT solution focused</li><li>Goal-driven delivery life cycle</li></ul><p>Now we will try to understand each key term in the context of DAD.</p><h4><strong>People First</strong></h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/972/0*uEj4Kh8qsK1YuQRo" /></figure><p>In DAD the “people first” idea is the main idea as the DAD process framework believes that people and the way that they collaborate are the primary determinants of success in IT efforts. DAD team members should be self-disciplined and the teams themselves should be self-organizing. In a team that uses the DAD process framework, There should be no hierarchy, and team members are encouraged to be cross-functional in their skill set and perform work related to disciplines other than their specialty.</p><p>The five primary roles of DAD are:</p><ol><li><strong>Stakeholder: </strong>The stakeholder is more than an end-user, someone who is materially impacted by the outcome of the solution. Examples of stakeholders are: a direct or indirect user, senior manager, or the one who funds the project.</li><li><strong>Product owner:</strong> The product owner represents the demands and desires of the stakeholder community to the agile delivery team. Examples of the responsibility of product owners are to clarify any details regarding the solution and for maintaining a prioritized list of work items that the team will implement to deliver the solution.</li><li><strong>Team member:</strong> The team member focuses on producing the actual solution for stakeholders. The team members might be responsible for tasks such as testing, analysis, architecture, design, programming, planning and more activities as required throughout the project.</li><li><strong>Team lead:</strong> The team lead is the agile coach, helping to keep the team focused on delivering work items and fulfilling their iteration goals and commitments that they have made to the product owner</li><li><strong>Architecture owner:</strong> The architecture owner makes the architecture decisions for the team and facilitates the creation and evolution of the overall solution design.</li></ol><h4><strong>Learning Oriented</strong></h4><p>The most effective organizations are the ones that promote a learning environment for their staff. There are three key ideas in a learning environment:</p><ul><li>Domain learning: how one is exploring and identifying what the stakeholders need.</li><li>Improving the process at an individual, team and enterprise levels.</li><li>Technical learning understanding how to work with the tools and technologies being used to craft the solution for the stakeholders.</li></ul><p>To support these ideas of learning the DAD process framework suggests strategies such as initial requirement envisioning, incremental delivery of a potentially consumable solution and for the team to identify potential process improvements</p><h4><strong>Agile</strong></h4><p>The DAD process framework adheres to and enhances the values and principles of the Agile Manifesto. High-quality results are achieved through techniques such as continuous integration, developer regression testing, test-first development, and refactoring.</p><h4><strong>A Hybrid Process Framework</strong></h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/730/0*ZsKH6Pq63ZbDc_Ly" /></figure><p>DAD is the formulation of many strategies and practices from both mainstream agile methods as well as other sources. Some examples of strategies and practice are Scrum, Extreme programming, Agile modeling, Unified process, Agile data, Kanban and more.</p><h4><strong>Solutions over Software</strong></h4><p>The DAD approach advances the focus from producing software to providing solutions which are where real business value lies for the stakeholders. The DAD approach promotes activities that address user experience (UX), database, business process, and documentation issues and more to help teams think beyond software development alone.</p><h4>Goal-driven Delivery Life Cycle</h4><p>The project lifecycle of the DAD approach is from the initial point to the construction point to the point of releasing into production.</p><p>There are three main stages and ongoing goals in the life cycle:</p><ol><li><strong>Inception Phase</strong>:<br>- Identify the vision for the project<br>- Bring stakeholders to an agreement around the vision<br>- Identify initial technical strategy, initial requirements, and project plan<br>- Form an initial team<br>- Secure funding<br>- Identify risks</li><li><strong>Construction Phase:</strong><br>- Produce a potentially consumable solution<br>- Address changing stakeholder needs<br>- Move closer to deployable release<br>- Maintain or improve upon existing levels of quality<br>- Address the highest risk(s)</li><li><strong>Transition Phase:</strong><br>- Ensure the solution is production-ready<br>- Ensure the stakeholders are prepared to receive the solution<br>- Deploy the solution into production</li></ol><p><strong>Ongoing goals:</strong></p><ul><li>Fulfill the project mission</li><li>Grow team members skills</li><li>Enhance existing infrastructure</li><li>Improve the team process and the environment</li><li>Leverage existing infrastructure</li></ul><h3><strong>What are the Framework’s Strengths and Weakness?</strong></h3><p><strong>Strengths:</strong></p><ul><li>Since it is a hybrid approach, the organization can use the best of each element which has been proven to create the best approach for the team.</li><li>Due to DAD flexibility, the team can adapt and modify to make their own approach that match their unique needs while still on the agile principle</li></ul><p><strong>Weakness:</strong></p><ul><li>DAD is not recommended for the team that is new to agile because it has no strict guidance to be follow correctly</li><li>The organization that adopt the DAD framework are likely to hire a professional consultant to guide their way through DAD as it has no guidance defined by the framework itself</li></ul><h3><strong>Summary</strong></h3><p>DAD does not give the exact procedure for the organization to follow. However, it gives guidance and recommends which tools and processes are needed for a particular situation depending on the project type and the organization goal.</p><p>Unfortunately, the adoption of DAD is not quite popular because only the small number of companies successfully integrate DAD to their business workflow. Most of them need to hire experienced consultants and coaches in order to fully utilize DAD to the best. This is particularly in the case of a large scale project or when the organization is transitioning from the traditional model.</p><p>The future of DAD stated by <a href="https://en.wikipedia.org/wiki/Scott_Ambler">Scott Ambler</a>, the author of a number of books focused on the Disciplined Agile Delivery toolkit, is:</p><blockquote>“The Disciplined Agile framework is constantly evolving. Right now we are in the process of releasing Disciplined Agile 2.0, which extends DAD into the IT space to explicitly address areas such as Enterprise Architecture, Portfolio Management Reuse Engineering, Disciplined DevOps, and many other key activities.”</blockquote><p><strong>Contributors</strong></p><ol><li><a href="https://medium.com/u/70af3aabad49">Manop Physics</a> (Manop Chugh) 60090016</li><li><a href="https://medium.com/u/117e5441b8a0">Napop Soontrapong</a> 60090019</li><li><a href="https://medium.com/u/c780cc49e941">Nattaphol Srisa</a> 59090014</li></ol><p>This article is a part of Software Development Process subject, Software Engineering International Program, KMITL, Thailand.</p><p><strong>References:</strong></p><ul><li><a href="https://medium.com/@media_75624/disciplined-agile-delivery-dad-cf0d1b6ffb13">https://medium.com/@media_75624/disciplined-agile-delivery-dad-cf0d1b6ffb13</a></li><li><a href="https://www.pmi.org/disciplined-agile/process/introduction-to-dad">https://www.pmi.org/disciplined-agile/process/introduction-to-dad</a></li><li><a href="https://www.agilest.org/scaled-agile/disciplined-agile-delivery-dad/">https://www.agilest.org/scaled-agile/disciplined-agile-delivery-dad/</a></li><li><a href="https://www.productplan.com/glossary/disciplined-agile/">https://www.productplan.com/glossary/disciplined-agile/</a></li><li><a href="https://disciplinedagileconsortium.org/Disciplined-Agile-DAD">https://disciplinedagileconsortium.org/Disciplined-Agile-DAD</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=190e29ca283f" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[[Part II] เขียนเว็บง่าย ๆ จากศูนย์ด้วย Ruby On Rails ? — MVC is easy!]]></title>
            <link>https://medium.com/@natpalmsl/part-ii-%E0%B9%80%E0%B8%82%E0%B8%B5%E0%B8%A2%E0%B8%99%E0%B9%80%E0%B8%A7%E0%B9%87%E0%B8%9A%E0%B8%87%E0%B9%88%E0%B8%B2%E0%B8%A2-%E0%B9%86-%E0%B8%88%E0%B8%B2%E0%B8%81%E0%B8%A8%E0%B8%B9%E0%B8%99%E0%B8%A2%E0%B9%8C%E0%B8%94%E0%B9%89%E0%B8%A7%E0%B8%A2-ruby-on-rails-mvc-is-easy-8a8b657ef1ff?source=rss-c780cc49e941------2</link>
            <guid isPermaLink="false">https://medium.com/p/8a8b657ef1ff</guid>
            <category><![CDATA[mvc]]></category>
            <category><![CDATA[web]]></category>
            <category><![CDATA[ruby-on-rails]]></category>
            <category><![CDATA[tutorial]]></category>
            <category><![CDATA[web-development]]></category>
            <dc:creator><![CDATA[Nattaphol Srisa]]></dc:creator>
            <pubDate>Mon, 27 Aug 2018 07:59:00 GMT</pubDate>
            <atom:updated>2018-08-27T07:59:00.581Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ZuniUw48GVy1vOSvsteyVw.png" /></figure><h3><strong>MVC ?</strong></h3><p>MVC MVC ? MVC ??? แน่นอน! เชื่อว่าหลาย ๆ คนถ้าหากเคยเรียน Software Patterns จาก CS หรือ CE มาจะต้องรู้จักกับคำนี้หรือคุ้นหูกันบ้างแหละ (คืนอาจารย์ไปหมดแล้ว!)</p><p>ลืมไปแล้วไม่เป็นไร เพราะวันนี้เราจะมาทำความรู้จักกับ MVC กัน!</p><h3>The MVC architecture</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wnMOB12yA8i2VlACOcRhvg.png" /><figcaption>Simple workflow of MVC Architecture</figcaption></figure><p>หากคิดจะทำ Rails แล้วล่ะก็ สิ่งที่ขาดไม่ได้เลยคือความเข้าใจเกี่ยวกับการทำงานของ MVC เพราะ Rails นั้นมองทุกอย่างเป็น MVC</p><p><strong>MVC</strong> ย่อมาจาก <strong>M</strong>odel, <strong>V</strong>iew, <strong>C</strong>ontroller</p><p>ซึ่งแต่ละส่วนก็จะทำงานแยกกันอย่างชัดเจน มีหน้าที่ที่จะต้องรับผิดชอบแตกต่างกันไป เรามาดูทีละส่วนกันดีกว่า</p><h4>Model</h4><blockquote>“ Maintains the relationship between Object and Database and handles validation, association and transactions “</blockquote><p>หมายความว่า Model จะทำหน้าที่เชื่อมโยงความสัมพันธ์กับฐานข้อมูล (database) ซึ่งแต่ละ Model จะเป็น<strong>ตัวแทน</strong>ของแต่ละ Table ในฐานข้อมูล (เช่น Model ชื่อว่า <em>User</em> ก็จะเชื่อมกับ table <em>Users</em> ในฐานข้อมูลของเรา) โดยที่ Model นี้แหละ จะเป็นตัวที่เราเอาไว้ใช้ <strong>ดู แก้ไข</strong> <strong>เปลี่ยนแปลง </strong>หรือ <strong>ลบ </strong>ข้อมูลในฐานข้อมูล (retrieve, save, edit, delete)</p><p>ว่าง่ายๆก็คือ Model จะทำตัวเป็นเหมือนผู้จัดการส่วนตัวของ database เราจะทำอะไรกับ database ก็ต้องมาทำผ่าน Model นั่นเอง</p><p>แล้วนอกจากที่กล่าวไปแล้ว Model ยังจะสามารถจัดการกับ <strong>การตรวจสอบข้อมูล</strong>(validations) และ <strong>ความสัมพันธ์ร่วมกัน</strong>(associations) ระหว่างแต่ละ Model ได้อีกด้วย</p><h4>View</h4><blockquote>“A presentation of data in a particular format, triggered by a controller’s decision to present the data.”</blockquote><p>คือ <strong>การแสดงผล</strong> output ตามที่ได้รับ request มา ซึ่งก็จะมีหลายรูปแบบ ไม่ว่าจะเป็นผ่านทาง <em>HTML, PDF, JSON</em> และอื่นๆ โดยผลลัพท์สุดท้ายที่ออกมาก็มักจะเป็นสิ่งที่เรียกว่า UI (User Interface) และถูกส่งไปยังผู้ใช้งาน (client)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xph76TlMtW9smf7ZZaTTwA.png" /><figcaption>views ในรูปแบบ html</figcaption></figure><p>หน้าเว็บไซต์ทั้งหมดที่เราเห็นก็คือ Views ในรูปแบบของ <em>HTML </em>นั่นแหละ</p><h4><strong>Controller</strong></h4><blockquote><em>“The facility within the application that directs traffic, on the one hand querying the models for specific data, and on the other hand organising that data (searching, sorting) into a form that fits the needs of a given view.”</em></blockquote><p>จะทำตัวเป็น<strong>หัวหน้าคุมงาน</strong>ทั้งหมด จัดการ search, query ข้อมูล, ทำการ render views ออกมา, ติดต่อสื่อสารกับ views models และ ควบคุม application logic ทั้งหมด</p><p>เชื่อว่าการอ่านอย่างเดียวคงไม่เห็นภาพเท่าไหร่ เพราะฉะนั้นเรามาลองลงมือทำกันจริง ๆ เลยดีกว่า</p><h3>1. Say “Hello”, Rails</h3><p>การจะทำให้ Rails สามารถแสดงผลคำว่า “Hello” ออกมาได้นั้น เราต้องสร้างอย่างน้อย ๆ สองอย่างนั่นคือ <em>controller</em> และ <em>view</em></p><p>จุดประสงค์ของ <em>controller</em> คือ การรับ <strong>request</strong> ที่ถูกส่งที่เข้ามาใน application, <em>Router </em>จะเป็นตัวตัดสินใจว่า <em>controller</em> ไหนจะจัดการ <strong>request </strong>นั้น และแต่ละ <strong>request </strong>ก็จะถูกจัดการโดย <em>action </em>ที่ต่างกันไป ลองดูภาพตัวอย่าง</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*o7FAxidtUJxF4uv3ml9Uew.png" /><figcaption>Routing, Controllers and Actions</figcaption></figure><p>ส่วนจุดประสงค์ของ <em>view</em> คือการแสดงผลออกมาให้คนอ่านรู้เรื่อง แต่สิ่งสำคัญที่ต้องอย่าสับสนคือ <em>controller </em>จะเป็นตัวรับข้อมูลต่างๆ ไม่ใช่ <em>views </em>ยกตัวอย่างเช่น เวลาเรากรอกข้อมูล ถึงแม้เราจะเห็นว่าเรากรอกลงไปในช่อง แต่ตัวที่รับข้อมูลเข้าไปจริงๆ คือ <em>controller </em>นั่นเอง โดย <em>views </em>ใน rails จะถูกเขียนด้วยภาษา eRuby (Embedded Ruby)</p><p>ต่อไปเราจะสร้าง controller ชื่อ Welcome และ action ชื่อ index โดยพิมพ์</p><pre>$bin/rails generate controller Welcome index</pre><p>จากนั้น rails จะ generate ไฟล์ต่างๆให้</p><pre>create  app/controllers/welcome_controller.rb<br> route  get &#39;welcome/index&#39;<br>invoke  erb<br>create    app/views/welcome<br>create    app/views/welcome/index.html.erb<br>invoke  test_unit<br>create    test/controllers/welcome_controller_test.rb<br>invoke  helper<br>create    app/helpers/welcome_helper.rb<br>invoke    test_unit<br>invoke  assets<br>invoke    coffee<br>create      app/assets/javascripts/welcome.coffee<br>invoke    scss<br>create      app/assets/stylesheets/welcome.scss</pre><p><em>controller </em>ที่เราสร้างจะอยู่ใน app/controllers/welcome_controller.rb <br>และ <em>view </em>จะอยู่ใน app/views/welcome/index.html.erb</p><p>เปิดไฟล์ app/views/welcome/index.html.erb ลบทุกอย่างข้างในทิ้งแล้วใส่ code นี้ลงไป</p><pre>&lt;h1&gt;Hello, Rails!&lt;/h1&gt;</pre><p>จากนั้นเข้าไปที่ <a href="http://localhost:3000/welcome/index">http://localhost:3000/welcome/index</a> ก็จะเจอกับหน้าเว็บแบบนี้<br>(อย่าลืมรัน bin/rails server เพื่อเปิดเซิร์ฟเวอร์ก่อน)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_bDtRXeb5JZWtoKQZdlGIw.png" /><figcaption><a href="http://localhost:3000/welcome/index">http://localhost:3000/welcome/index</a></figcaption></figure><h3>2. Setting the Application Home Page</h3><p>เอาล่ะ ตอนนี้เราได้สร้าง controller กับ views เรียบร้อยแล้ว ถ้าลองเข้าไปที่ <a href="http://localhost:3000/">localhost:3000</a> ก็จะพบว่าไม่มีอะไรเกิดขึ้น (อ้าว!) นั่นเพราะเราจำเป็นต้องบอก rails ก่อนว่าเราต้องการให้หน้า “Hello, Rails!” แสดงออกมาตอนไหน</p><p>เปิดไฟล์ config/routes.rb ขึ้นมาจะเป็นหน้าตาแบบนี้</p><pre>Rails.application.routes.draw do</pre><pre>  get <em>&#39;welcome/index&#39;<br>  <br>  </em># For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html</pre><pre>end</pre><p>ไฟล์ routes.rb นี้จะเป็นไฟล์ที่จะเชื่อม request ที่เข้ามากับ controller และ action บรรทัด get ‘welcome/index’ เป็นส่วนที่ถูกเพิ่มมาทีหลังพร้อมกับตอนที่เรารันคำสั่ง bin/rails generate controller Welcome index</p><p>เพิ่มบรรทัด root ‘welcome/index’ เข้าไปที่ไฟล์</p><pre>Rails.application.routes.draw do</pre><pre>  get <em>&#39;welcome/index&#39;</em></pre><pre>  root <em>&#39;welcome#index&#39;</em></pre><pre>end</pre><p>root ‘welcome#index’ จะบอก rails ว่า ถ้าหากมีคนเข้ามาที่ root (ในที่นี้คือ <a href="http://localhost:3000/">localhost:3000</a>) จะถูกส่งไปจัดการโดย controller ชื่อ welcome และ action ชื่อ index</p><p>ส่วน get ‘welcome/index’ จะบอก rails ว่า ถ้ามีคนเข้าไปที่ <a href="http://localhost:3000/welcome/index">localhost:3000/welcome/index</a> ก็จะถูกส่งไปจัดการโดย controller ชื่อ welcome และ action ชื่อ index เช่นกัน</p><p>หลังจากเราเพิ่ม root ให้ rails แล้ว ทีนี้ลองเข้าไปที่ <a href="http://localhost:3000/">localhost:3000</a> ก็จะพบว่าหน้าตาเหมือนกับ <a href="http://localhost:3000/welcome/index">localhost:3000/welcome/index</a> เพราะถูกจัดการด้วย controller และ action เดียวกันนั่นเอง<br>(สำหรับการ routing แบบ ละเอียดยิบ เข้าไปดูได้ที่ <a href="https://guides.rubyonrails.org/routing.html">Rails Routing from the Outside In</a>)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gBX7m3VHEzozCx2GyMmKbQ.png" /><figcaption><a href="http://localhost:3000/">localhost:3000</a></figcaption></figure><p>สำหรับพาร์ทต่อไปเราจะลงมือเขียนเว็บ blog ของเราขึ้นมาเองจาก Ruby on Rails รอติดตามต่อกันได้เลย</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8a8b657ef1ff" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[[Part I] เขียนเว็บง่าย ๆ จากศูนย์ด้วย Ruby On Rails ? — Let’s be on Rails]]></title>
            <link>https://medium.com/@natpalmsl/%E0%B9%80%E0%B8%82%E0%B8%B5%E0%B8%A2%E0%B8%99%E0%B9%80%E0%B8%A7%E0%B9%87%E0%B8%9A%E0%B8%87%E0%B9%88%E0%B8%B2%E0%B8%A2%E0%B9%86%E0%B8%88%E0%B8%B2%E0%B8%81%E0%B8%A8%E0%B8%B9%E0%B8%99%E0%B8%A2%E0%B9%8C%E0%B8%94%E0%B9%89%E0%B8%A7%E0%B8%A2-ruby-on-rails-part-i-840749ecc4e8?source=rss-c780cc49e941------2</link>
            <guid isPermaLink="false">https://medium.com/p/840749ecc4e8</guid>
            <category><![CDATA[tutorial]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[datawow]]></category>
            <category><![CDATA[ruby]]></category>
            <category><![CDATA[ruby-on-rails]]></category>
            <dc:creator><![CDATA[Nattaphol Srisa]]></dc:creator>
            <pubDate>Mon, 02 Jul 2018 02:58:08 GMT</pubDate>
            <atom:updated>2019-10-31T18:03:55.558Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*FfZaSvKNAaKR6CfHRzTd7w.jpeg" /></figure><p>เนื่องจากได้มีโอกาสไปฝึกงานที่บริษัท<a href="https://datawow.io/"> Data Wow Co., Ltd. </a>บริษัทที่ CEO โคตรจะป๋าและเปย์หนักมากที่สุดเท่าที่เคยเจอมา(ก็เคยทำบริษัทเดียว) เลยได้เริ่มต้นลองเขียนเว็บด้วย Ruby On Rails (ROR) เป็นครั้งแรก แล้วก็พบว่ามันเป็นอะไรที่เจ๋งมาก! เจ๋งยังไง? อะยกตัวอย่างเช่น ชื่อคราสจะตั้งชื่อมั่วซั่วไม่ได้ เติม s, es ผิดที เจ้านี่ก็จะ งง! (ห๊าาาา) ใช่แล้ว ฟังไม่ผิด ROR จะใส่ใจกับการเติม s, es มาก เพราะถ้าเราเขียนถูกแล้วล่ะก็ Rails จะสามารถลิ้งค์ความสัมพันธ์ระหว่างคลาสให้เราได้แบบออโต้ อย่างกับเวทมนต์ยังไงอย่างงั้น</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/275/1*ljTFIMmjzU5_IxkLssllAA.gif" /></figure><h3>Ruby คืออะไร?</h3><p>แน่นอนว่าก่อนที่เราจะเริ่มต้นกับ Ruby On Rails แน่นอนว่าเราต้องรู้จักกับแกนหลักของมันซะก่อน</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/196/1*3hVPiIItu5-_hKN66tKqcw.jpeg" /></figure><p>Ruby เป็นภาษาคอมพิวเตอร์ประเภทหนึ่ง ซึ่งมีลักษณะการแปล source code แบบ interpreter (อ่านทีละบรรทัด) คล้ายกับ Python หรือ Perl เป็นภาษาที่มีการเขียนแบบ script object oriented ซึ่งสนับสนุนการเขียน OOP แบบเต็มขั้น!</p><p>Ruby จะพยายามทำให้ syntax ของตัวเองสั้น กระชับและซับซ้อนน้อยที่สุด โดยมักจะมีคนบอกว่า Ruby จะรวมข้อดีของ Perl และ Python เอาไว้ สิ่งไหนที่มีใน Perl แต่ไม่มีใน Python หรือสิ่งไหนที่มีใน Python แต่ไม่มีใน Perl มักจะพบอยู่ในภาษา Ruby นั่นเอง</p><p>Ruby ถูกคิดค้นและพัฒนาโดยชาวญี่ปุ่นชื่อว่า Yukihiro Matsumoto และปล่อยเวอร์ชั่น 1.0 ในช่วงปลายปี ค.ศ. 1996 (22 ปีมาแล้ว)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*TsECWDoffJetqfiSv1EIiQ.jpeg" /></figure><h3>Ruby On Rails คืออะไร?</h3><p>Ruby On Rails หรือ ROR (ต่อไปจะเรียกสั้น ๆ ว่า <em>Rails </em>แล้วกัน) นั้นเป็น open source <a href="http://www.atthakorn.com/%E0%B8%97%E0%B8%B3%E0%B9%84%E0%B8%A1%E0%B9%80%E0%B8%A3%E0%B8%B2%E0%B8%96%E0%B8%B6%E0%B8%87%E0%B8%95%E0%B9%89%E0%B8%AD%E0%B8%87%E0%B9%83%E0%B8%8A%E0%B9%89-framework/">web application framework</a> ที่ถูกพัฒนาด้วยภาษา Ruby โดยที่ Rails นั้นจะมีโครงสร้างการจัดการแบบ <a href="https://blog.codinghorror.com/understanding-model-view-controller/">Model View Controller</a> ซึ่งมีข้อดีคือ <br>1. มีการออกแบบที่ชัดเจน มองภาพรวมได้ง่าย<br>2. ปรับปรุง/แก้ไข ระบบได้โดยง่าย เพราะแต่ละส่วนแยกกันอย่างชัดเจน<br>3. maintain ระบบได้ง่าย เพราะมีโครงสร้างชัดเจน จึงทำให้ยืดหยุ่นต่อการเพิ่มเติม รวมไปถึงการนำส่วนต่าง ๆ ไปใช้ซ้ำได้ด้วย</p><p>อีกทั้ง Rails ยังถูกพัฒนาขึ้นมาเพื่อให้แอพพลิเคชั่นถูกพัฒนาด้วยโค้ดที่น้อยกว่า framework อื่นอย่างมาก และมี configuration ที่น้อยที่สุด เพื่อให้ง่ายต่อการนำไปประยุกต์ใช้</p><p>Rails ยึดกับหลักการ DRY(Don’t Repeat Yourself) ก็คือ สิ่งไหนที่เคยทำแล้ว จะไม่ทำซ้ำ จะเขียนแต่ละองค์ประกอบให้เล็กที่สุดเพื่อการนำไปใช้ต่อ ทำให้เราไม่ต้องมานั่ง Ctrl-C Ctrl-V กันรัว ๆ นั่นเอง</p><p>เพื่อไม่ให้เป็นการเสียเวลา เรามาลอง setup rails server ครั้งแรกกันเลยดีกว่า</p><h3>1. Installing Ruby with RBENV</h3><p>ก่อนที่เราจะทำการติดตั้ง Rails แน่นอนว่าเราต้องทำการติดตั้ง Ruby ก่อน ซึ่งวิธีที่ง่ายที่สุดก็คือการใช้ตัว ruby version manager อย่าง <a href="https://github.com/rbenv/rbenv">RBENV</a> หรือ <a href="https://github.com/rvm/rvm">RVM</a> นั่นเอง</p><p>ทั้งสองตัวจะเป็นตัวที่ใช้ในการจัดการ ruby version ในเครื่องของเรา เพราะในชีวิตจริง แต่ละโปรเจคก็จำเป็นต้องใช้ ruby คนละเวอร์ชั่นกัน จะลบลงใหม่ไป ๆ มา ๆ ก็ใช่เรื่อง เลยเกิดเป็น ruby version manager ขึ้นมา</p><p>ในที่นี้จะขอเลือกใช้ rbenv ส่วนใครที่ใช้ rvm อยู่แล้วหรืออยากจะใช้ rvm ก็กดลิ้งค์ไปดู<a href="https://github.com/rvm/rvm#installing-rvm">วิธีติดตั้ง</a>จากลิ้งค์ได้เลย</p><h4>1.1 Installing RBENV on macOS</h4><ol><li>ติดตั้ง rbenv ผ่าน brew ใน Terminal<br>(สำหรับใครที่ยังไม่มี brew ก็เข้าไปโหลด<a href="https://brew.sh/">ที่นี่</a>เลย)</li></ol><pre>$ brew install rbenv</pre><p>2. เริ่มต้น rbenv โดย</p><pre>$ rbenv init</pre><p>3. คัดลอกให้ rbenv รันทุกครั้งที่เปิด command line</p><pre>$ eval &quot;$(rbenv init -)&quot; &gt;&gt; ~/.bashrc</pre><p>ถ้าใช้ zsh ให้เปลี่ยน .bashrc เป็น .zshrc แทน</p><p>4. โหลดไฟล์ใหม่</p><pre>$ source $HOME/.bash_profile</pre><p>5. เช็คว่า rbenv ใช้งานได้แล้วโดย ใช้ rbenv-doctor</p><pre>$ curl -fsSL <a href="https://github.com/rbenv/rbenv-installer/raw/master/bin/rbenv-doctor">https://github.com/rbenv/rbenv-installer/raw/master/bin/rbenv-doctor</a> | bash</pre><p>ถ้าขึ้นว่า</p><pre>Checking for `rbenv&#39; in PATH: /usr/local/bin/rbenv<br>Checking for rbenv shims in PATH: OK<br>Checking `rbenv install&#39; support: /usr/local/bin/rbenv-install (ruby-build 20170523)<br>Counting installed Ruby versions: none<br>  There aren&#39;t any Ruby versions installed under `~/.rbenv/versions&#39;.<br>  You can install Ruby versions like so: rbenv install 2.2.4<br>Checking RubyGems settings: OK<br>Auditing installed plugins: OK</pre><p>ก็แสดงว่าเป็นอันเสร็จเรียบร้อย</p><h4>1.2 Installing RBENV on Linux</h4><p><a href="https://www.digitalocean.com/community/tutorials/how-to-install-ruby-on-rails-with-rbenv-on-ubuntu-16-04">ดูได้ที่นี่</a></p><h4>1.3 Installing RBENV&amp;RVM on Windows</h4><p><a href="https://gorails.com/setup/windows/10">ดูได้ที่นี่</a></p><h4>1.4 Installing Ruby with RBENV</h4><p>1. ติดตั้ง ruby เวอร์ชั่น 2.6.5 โดย รันคำสั่ง</p><pre>$ rbenv install 2.6.5</pre><p>ใช้เวลานานซักนิด ผลลัพธ์ที่ได้ก็จะออกมาเป็นประมาณนี้</p><pre>ruby-build: use openssl from homebrew<br>Downloading ruby-2.6.5.tar.bz2...<br>-&gt; <a href="https://cache.ruby-lang.org/pub/ruby/2.5/ruby-2.5.1.tar.bz2">https://cache.ruby-lang.org/pub/ruby/2.6/ruby-2.6.5.tar.bz2</a><br>Installing ruby-2.5.1...<br>ruby-build: use readline from homebrew<br>Installed ruby-2.6.5 to /Users/abc/.rbenv/versions/2.6.5</pre><p>เท่านี้เราก็จะมี ruby version 2.6.5 บนเครื่องแล้ว ง๊ายง่ายใช่มั้ยล่ะ</p><p>เอาล่ะ ถึงเวลาได้ทำแอพจริง ๆ สักที ต่อไปเราจะทำการเซ็ทอัพ Rails server บนเครื่องของเรา ไว้ใช้ทดสอบเวลาที่เราเขียนเว็บนั่นเอง</p><h3>2. Setup Our First Rails Application</h3><h4>2.1 Installing Rails</h4><p>1. เปิด Terminal ขึ้นมาแล้วพิมพ์</p><pre>$ cd ~/Desktop<br>$ mkdir my_rails_app<br>$ cd my_rails_app</pre><blockquote><strong>Note:</strong> cd = change directory, mkdir = make directory ถ้าหากใครยังไม่คล่องกับคำสั่งพื้นฐานใน Terminal แนะนำให้ไปฝึกมาก่อน เพราะในการพัฒนาด้วย Rails เราจะใช้ Terminal กันเยอะมากครับ</blockquote><p>2. ตั้งค่าให้เฉพาะ directory นี้ใช้ ruby เวอร์ชั่น 2.6.5 โดย</p><pre>$ rbenv local 2.6.5</pre><p>หรือถ้าอยากจะเปลี่ยนเวอร์ชั่นก็แค่เปลี่ยนเลขของเวอร์ชั่น rbenv ก็จะจัดการให้เอง</p><p>3. gem คือ Ruby Package Manager ที่จะช่วยเราจัดการกับ libraries ต่างๆ คล้ายๆกับ npm ของ javascript ซึ่งเวลาติดตั้งต่างๆ gem จะสร้าง local document ไว้ด้วยทำให้ช้า เราสามารถปิดการทำงานของมันได้</p><pre>$ echo &quot;gem: --no-document&quot; &gt; ~/.gemrc</pre><p>4. ติดตั้ง <a href="https://bundler.io/">Bundler</a> ผ่าน gem ซึ่งเป็นตัวช่วยจัดการ dependencies ต่างๆของ rails</p><pre>$ gem install bundler</pre><p>5. ติดตั้ง rails พระเอกของเรา ซึ่งเราจะเลือกเป็นเวอร์ชั่น 6.0.0</p><pre>$ gem install rails -v 6.0.0</pre><p>6. ทุกๆครั้งที่เราติดตั้ง gem ที่มี command ติดมาด้วยเช่น rails เป็นต้น เราจะต้องทำการ rehash เสมอเพื่อให้สามารถเรียก command ใหม่ที่ติดตั้งมาได้</p><pre>$ rbenv rehash</pre><p>ถ้าติดตั้งเสร็จเรียบร้อยแล้ว หากพิมพ์ $ rails --version ก็จะขึ้นประมาณว่า Rails 6.0.0 แบบนี้ถือว่าสำเร็จ</p><h4>2.2 Installing Database</h4><p>1. ติดตั้ง Database ผ่าน brew โดยในที่นี่จะเลือกใช้ Postgresql</p><pre>$ brew install postgresql</pre><p>2. ใส่ postgresql ลงใน PATH เพื่อให้สามารถเรียกใช้คำสั่งได้<br>อย่าลืมเปลี่ยนเลข <strong>11</strong> เป็นเลขเวอร์ชั่นของ postgresql ที่เราติดตั้งไป</p><pre>$ echo &#39;export PATH=&quot;/usr/local/opt/postgresql@<strong>1</strong>1/bin:$PATH&quot;&#39; &gt;&gt; ~/.bash_profile</pre><p>ถ้าใช้ zsh ให้เปลี่ยน .bash_profile เป็น .zshrc เช่นเคย</p><p>3. โหลดไฟล์ .bash_profile ใหม่</p><pre>$ source ~/.bash_profile</pre><p>4. ตั้งให้ postgresql เริ่มต้นทุกครั้งที่ login</p><pre>brew services start postgresql@11</pre><p>5. เชคเวอร์ชั่นของ postgresql ว่าติดตั้งถูกต้อง</p><pre>postgres -V</pre><p>จะได้ output เป็น ประมาณนี้postgres (PostgreSQL) 11.5</p><p>6. โดยปกติแล้วหากติดตั้ง postgres ผ่าน homebrew จะสร้าง superuser role ให้เราโดยใช้ชื่อเดียวกับ username ของ macOS เรา แต่เราจะสร้าง user ใหม่เพื่อให้ สิทธิของ superuser ไม่ไปปะปนเวลาเราทำงานบน rails<br>เปลี่ยน <strong>appname </strong>เป็นชื่อที่เราต้องการ</p><pre>$ createuser -P -d <strong>appname</strong></pre><p>-d หมายความว่าเราจะให้สิทธิในการสร้าง database กับ user นี้</p><p>-P จะใส่เราใส่ password ทันทีหลังรันคำสั่ง อย่าลืมจำพาสเวิร์ดที่เราใส่ไว้ด้วย เพราะเราจะต้องใช้อีกทีตอนติดตั้ง rails</p><h4>2.3 Create the Blog Application</h4><p>Rails นั้นจะมาพร้อมกับ script และ generator จำนวนนับไม่ถ้วน ที่ถูกออกแบบมาเพื่อให้ชีวิตของนักพัฒนาง่ายขึ้น โดย Rails จะทำการ generate โค้ดส่วนที่สำคัญ ๆ มาให้เราแล้วหลายอย่างซึ่งต่างจากภาษาโปรแกรมมิ่งอื่น ๆ ที่เราต้องเขียนเองแทบจะทั้งหมด เพราะฉะนั้นก็อย่าตกใจไปกับจำนวนไฟล์มหาศาลที่ Rails สร้างขึ้นมาให้ แล้วทำใจให้ชินซะเพราะเราจะได้ generate กันอีกเยอะแน่นอน</p><p>ซึ่ง Rails ก็ต้อนรับเราอย่างดีด้วยการจัดตัวช่วยสร้างแอพพลิเคชั่นมาให้เลยง่าย ๆ <br>เปิด Terminal แล้วเข้าไปที่โฟลเดอร์ที่เราจะสร้างโปรเจค (ซึ่งเราสร้างไปแล้วใน section 2.1.1 ชื่อว่า my_rails_app) แล้วพิมพ์:</p><pre>$ rails new blog --database=postgresql</pre><p>ด้วยคำสั่งนี้ Rails จะทำการสร้าง directory ชื่อว่า blog (คือชื่อเว็บของเราเอง) แล้วสร้างไฟล์สำคัญ ๆ มาให้มากมาย รวมทั้งติดตั้ง GEM อื่น ๆ ที่จำเป็นกับโปรเจคของเรา (gem dependencies) ให้เราแบบอัตโนมัติด้วย</p><p>เข้าไปที่โฟลเดอร์ blog ด้วย $ cd blog ก็จะพบกับไฟล์ต่าง ๆ โดยแต่ละไฟล์ก็จะทำหน้าที่ต่าง ๆ กันไป โดยหลังจากนี้เราจะทำงานกันในโฟลเดอร์ app/ ส่วนโฟลเดอร์อื่น ๆ มีดังนี้:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3c50e1575383f94788546396dd1be969/href">https://medium.com/media/3c50e1575383f94788546396dd1be969/href</a></iframe><h4>2.4 Database Configuration</h4><ol><li>rails จะสร้าง development และ test database ให้เรา โดยจะใช้ user role ที่เราสร้างขึ้นมาใน 2.2 แต่ก่อนอื่นเราต้องหาที่เก็บพาสเวิร์ดของเราไว้ก่อน<br>เปลี่ยน APPNAME เป็นชื่อเดียวกับที่เราตั้งไว้และ PostgreSQL_Role_Password เป็นพาสเวิร์ดของเรา</li></ol><pre>$ echo &#39;export <strong>APPNAME</strong>_DATABASE_PASSWORD=&quot;<strong>PostgreSQL_Role_Password</strong>&quot;&#39; &gt;&gt; ~/.bash_profile</pre><p>2. โหลดไฟล์ .bash_profile ใหม่</p><pre>$ source ~/.bash_profile</pre><p>3. เปิดไฟล์ blog/config/database.yml ด้วย editor ที่ชื่นชอบ แล้วไปที่เซคชั่น default หาบรรทัดที่เขียนว่า pool: &lt;%= ENV.fetch(&quot;RAILS_MAX_THREADS&quot;) { 5 } %&gt; แล้วเพิ่มบรรทัด <strong>username</strong> กับ <strong>password</strong> ลงไป อย่าลืมเปลี่ยน username ให้ตรงกับที่เราสร้างไว้ก่อนหน้านี้</p><pre>...<br>default: &amp;default<br>  adapter: postgresql<br>  encoding: unicode<br>  # For details on connection pooling, see Rails configuration guide<br>  # http://guides.rubyonrails.org/configuring.html#database-pooling<br>  pool: &lt;%= ENV.fetch(&quot;RAILS_MAX_THREADS&quot;) { 5 } %&gt;<br>  <strong>username: appname<br>  password: &lt;%= ENV[&#39;APPNAME_DATABASE_PASSWORD&#39;] %&gt;</strong><br><br>development:<br>  &lt;&lt;: *default<br>  database: blog_development<br>...</pre><p>4. หลังจากตั้งค่าไปหมดเรียบร้อยแล้ว ให้สร้าง database ผ่านคำสั่ง</p><pre>$ rails db:create</pre><p>จะได้ output ออกมาประมาณนี้ ถือว่าเสร็จเรียบร้อย</p><pre>Created database &#39;appname_development&#39;<br>Created database &#39;appname_test&#39;</pre><h3>3. Hello, Rails!</h3><p>เมื่อทำทุกอย่างเสร็จสรรพเรียบร้อยแล้ว เวลาที่เราทำงานกับ Rails เราก็จะต้องมีตัวอย่างแสดงผลว่าทำอะไรไปแล้วบ้าง หน้าตาเป็นยังไง ใช่ไหม? แน่นอนว่า Rails ก็จัดให้ โดย Rails นั้นมี tools ที่ช่วยให้เราสามารถเปิดเซิร์ฟเวอร์บนเครื่องของเราเองได้ (localhost) พิมพ์</p><pre>$ rails server</pre><blockquote><strong>Note: </strong>สำหรับ Windows จะต้องเรียกไฟล์ rails มาจากโฟล์เดอร์ <em>bin</em> ของ Ruby เองโดยพิมพ์ <em>$ ruby bin/rails server</em></blockquote><p>คำสั่งนี้จะทำการรัน Puma ซึ่งเป็นเว็บเซิร์ฟเวอร์ที่ติดตั้งมาพร้อมกับ Rails แต่แรก<br>จากนั้นเปิดเบราว์เซอร์ (chrome, safari, etc.) แล้วเข้าไปที่ url</p><pre><a href="http://localhost:3000/">http://localhost:300</a>0</pre><p>ถ้าพบกับหน้าตาแบบนี้ก็แสดงว่าทุกอย่าง setup ถูกต้องเรียบร้อยดี พร้อมสำหรับเขียนเว็บของเราแล้วล่ะ!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hQOr4L5Q2yC6mdCBZ-lJQg.png" /><figcaption>เข้าไปที่ <a href="http://localhost:3000/">http://localhost:3000</a> ก็จะพบกับหน้านี้</figcaption></figure><p>สำหรับพาร์ทต่อไปเราจะมาดูกันเรื่อง MVC และ routing ของ Rails รอติดตามกันได้เลย<br><a href="https://blog.datawow.io/part-ii-%E0%B9%80%E0%B8%82%E0%B8%B5%E0%B8%A2%E0%B8%99%E0%B9%80%E0%B8%A7%E0%B9%87%E0%B8%9A%E0%B8%87%E0%B9%88%E0%B8%B2%E0%B8%A2-%E0%B9%86-%E0%B8%88%E0%B8%B2%E0%B8%81%E0%B8%A8%E0%B8%B9%E0%B8%99%E0%B8%A2%E0%B9%8C%E0%B8%94%E0%B9%89%E0%B8%A7%E0%B8%A2-ruby-on-rails-mvc-is-easy-8a8b657ef1ff">[Part II] เขียนเว็บง่าย ๆ จากศูนย์ด้วย Ruby On Rails ? — MVC is easy!</a></p><blockquote><strong>​Note: </strong>หรือถ้าหากใครที่ไม่ต้องการเปิดบนเครื่องของตัวเอง ลองเข้าไป<a href="https://www.railstutorial.org/book/beginning#sec-development_environment">อ่านในนี้</a>ได้ เล่มนี้จะสอนวิธี ​setup บน cloud ของ AWS (Amazon Web Service) ทำทุกอย่างบนคลาวด์ก็สะดวกไปอีกแบบครับ</blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=840749ecc4e8" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>