<?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 James Jeonggyu Kong on Medium]]></title>
        <description><![CDATA[Stories by James Jeonggyu Kong on Medium]]></description>
        <link>https://medium.com/@jamesjeonggyukong?source=rss-41741a38bbad------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*dEfSLwYDdtQL6u-H6p-ymQ.jpeg</url>
            <title>Stories by James Jeonggyu Kong on Medium</title>
            <link>https://medium.com/@jamesjeonggyukong?source=rss-41741a38bbad------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 01 Dec 2026 21:35:06 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@jamesjeonggyukong/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[Part 4. Create a simple web application using Rails framework]]></title>
            <link>https://medium.com/@jamesjeonggyukong/part-4-create-an-simple-web-application-using-rails-framework-66e375d4aba9?source=rss-41741a38bbad------2</link>
            <guid isPermaLink="false">https://medium.com/p/66e375d4aba9</guid>
            <category><![CDATA[ruby-on-rails]]></category>
            <category><![CDATA[rails]]></category>
            <dc:creator><![CDATA[James Jeonggyu Kong]]></dc:creator>
            <pubDate>Wed, 22 Mar 2017 04:44:46 GMT</pubDate>
            <atom:updated>2017-04-08T03:58:57.312Z</atom:updated>
            <content:encoded><![CDATA[<h3>Introduction</h3><p>On the previous post, I have talked about Rails framework and key components. As I mentioned in conclusion of previous post, I will create an blog post website using Rails framework. In other words, I will create CRUD(Create, Read, Update, Delete) application. Through this post, you could learn how to generate a web application using rails framework.</p><h3>Prerequisites</h3><p>Before creating web application on Linux, you should install Rails framework with Ruby on your Linux machine such as what I did in <a href="https://medium.com/@jamesjeonggyukong/part1-set-up-environments-for-ruby-on-rails-on-linux-server-9e35d9d50306#.1upe5b25a"><strong><em>first blog post</em></strong></a>. And you have to see a screen like below by running server using<strong> ‘rails s’ </strong>or <strong>‘rails server’</strong> command.</p><figure><img alt="" src="https://cdn-images-1.medium.com/proxy/1*sTapfSE_LjpybaPSeC-9qQ.png" /></figure><p>If you see this screen on your browser when you access to localhost:3000, You are ready to start developing rails project.</p><h3>Generate a rails project</h3><p>To generate a project of rails, we need to type one command line on terminal.</p><pre>$ rails new project1 --skip-bundle</pre><p>This command line means you are going to create a rails project called project1 without installing bundle.</p><p>The reason why using option in the end of line of the command is that we need to do a setting before running project. After generating a project, you could see that there is a folder called project1. To do setting, you have to edit Gemfile in the project1 folder.</p><pre>$ cd project1<br>$ gedit Gemfile</pre><p>You could see that there is a line that has “<strong>gem ‘therubyracer’, platforms: :ruby</strong>”. Found this line and remove comment to use this dependency. It means that you are going to use ruby for this project as a platforms. After doing this, you can install dependencies. Run below command.</p><pre>$ bundle install</pre><p>If you run this command, bundles are installed and you can see below screen.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/713/1*OhLKCpiwtvHEEzZWOBgRcA.png" /><figcaption>Bundles are installed</figcaption></figure><p>After that, you can run server using below command.</p><pre>$ rails server</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/695/1*DasjYqT0BrLi1PdBNvSdCg.png" /><figcaption>Rails server is running</figcaption></figure><p>As I did in the first post, if you try to have access to localhost:3000, you are going to see default web page. If you see this page, your server is up now in the localhost.</p><h3><strong>Structure of Rails project</strong></h3><p>Now, Let’s take a look what structure of this project is. If you go to folder of the project generated, you could see many folders such as below screenshot.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/731/1*ZTArJvEnw0nXdNn0PspSQg.png" /><figcaption>Structure of rails project</figcaption></figure><p>First, In app directory, there is a controller folder where controllers components are gathered. And in the view folder, html files for view components are gathered. In the model folder, it has all of model components. We are going to usually use those three folders for blog website. The routes.rb file that specifies the routing rules is located in the config directory. We can route user to specific URL using this file. In addition, we could see database.yml that is a file for settings of database in Config folder. Lastly, As we did when we are creating project, Gemfile allows you to specify which dependencies will be used for your web application.</p><h3>1. Create Model and Database</h3><p>To create CRUD application, the first thing we have to do is generating model. It’s because we can migrate database through generating model in Rails framework.</p><pre><strong>$ rails generate model Post</strong><br><em>Syntax: rails generate model [model name]</em></pre><p>If you type above command line, you could see messages on the screen.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/721/1*2CkmlxcyHYotXyzDknSWkQ.png" /></figure><p>From this message, a migration file is generated in the path of “db/migrate”. Also, we can see that post.rb file is generated in models folder. To migrate database for model component, we should edit this file.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/403/1*V0z6b8pOIqABJnqw1UlZDQ.png" /></figure><p>If you take a look at the migration file, this class inherits ActiveRecord Class. What we need to do is to specify the name and type of columns for database table. So, for this blog web application, we would use title, content and writer. And data types for each column will be string, text and string respectively.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/404/1*qQLmxOWw0jbvWMy1V8dSGA.png" /></figure><p>So I would add those three lines to create columns in database table. So I specified data type before the name of column. After editing this file, to create table on database, we should run a below command.</p><pre>$ rake db:migrate</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/710/1*Q0cHGg8443uiZTfbUN2LbQ.png" /><figcaption>Generate Table</figcaption></figure><p>This command is generating table on database. We could access to database using Post model. And you can check this on Rails console.</p><pre>$ rails console</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/614/1*1uxWRzt6I2GhZhCNj3fWqA.png" /><figcaption>Rails Console</figcaption></figure><p>In the rails console, you can see how to manipulate your database using methods of model.</p><h3>How to manipulate database using model</h3><h4><strong>1) Get all of records on table of database: Post.all</strong></h4><blockquote><strong>Syntax: [Model Name].all</strong></blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/464/1*1bqCdQztEcwQLyknkRr0lg.png" /></figure><p>This command is to show user all of lines of database as a format of array. For now, we don’t have any data on this table, so it is returning empty array.</p><h4>2) Check the schema of table: Post</h4><blockquote>Syntax: [Model Name]</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/717/1*A_nIVG8vPokfLPDTdEO8sw.png" /></figure><h4>3) Create a record of table: Post.create(values)</h4><blockquote>Syntax: [Model Name].create</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/721/1*jGEdrQj1sHOw1FuHCh9ojA.png" /></figure><p>As you see in the first line of screen shot, if you use create method, it generates a line of record. And in the parentheses, you should give each value to the column. There is column for id, which is generated automatically. This column is auto-increment value. Moreover, you can see that the date and time for creating and updating record is recorded in the two columns.</p><h4>4) Retrieve a record of table using id: Post.find(id)</h4><blockquote>Syntax: [Model Name].find(id)</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/725/1*9QGjzztjyKACtz4FZN3Qog.png" /></figure><p>If you give a value of id to find method, it is searching for a record based on id value.</p><h4>5) Retrieve a record of table using specific column: Post.find_by_name(name)</h4><blockquote>Syntax: [Model Name].find_by_[name of column](value)</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/723/1*uPEPFVp574M23MBvh33wPw.png" /></figure><p>If you use this method, you can use any other columns’ name for searching record.</p><h4>6) Edit a record of table</h4><p>There are three steps for editing a record.</p><blockquote><strong>6–1) Retrieve a record which need to be edit and put a record into a variable.</strong></blockquote><p>record = Post.find(1)</p><blockquote><strong>6–2) Change the values of specific column</strong></blockquote><p>record.writer = “user”</p><blockquote><strong>6–3) Save the record using save method</strong></blockquote><p>record.save #commit the changed data to the database</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/842/1*dqCgF2ZLrIidJokCReThcw.png" /><figcaption>Edit a record of database</figcaption></figure><h4>7) Delete a record from database: record.destroy</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*k8TUkA82nlOGvP8ICLDwxQ.png" /><figcaption>Delete a record</figcaption></figure><p>Deleting a record is simple. After retrieving a record to the variable, you just need to call destroy method.</p><p>As you see in the above examples, in the rails project, we can manipulate database using simple method of model. We are going to use this way for creating CRUD web application.</p><h3>2. Create Controller and View</h3><p>Now, since we created a model and database for blog web application, what do we have to create more? That’s right. We need to create view and controller. First, Let’s create controller.</p><pre>$ rails generate controller post<br>Syntax : rails generate controller [name of controller]</pre><p>If you run above command, you could see same screen with below screenshot. As you see in screenshot, rails is generating a file for controller in controllers folder and a folder in views folder.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/653/1*ZwYgzrrupqXGz8_cnHzhdw.png" /><figcaption>Create Controller</figcaption></figure><ul><li><strong>app/controllers/post_controller.rb : Controller file</strong></li><li><strong>app/views/post/: folder for controller’s view</strong></li></ul><p>You can edit controller file in the controllers folder and create view file in post folder in the folder of views. As you might notice it, folder’s name for view is following controller’s name. It means that view files that are in the post folder will be used for this controller. Go to the path of controller and open controller file.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/414/1*VYPcHVfLGknLRFFy0U30Kg.png" /><figcaption>Controller file</figcaption></figure><p>When you open the post_contoller.rb, there are only codes for class. The first line means PostController class inherits ApplicationController class. By the way, there is nothing special without codes for class. Now we are going to make a method in this controller class which is called <strong><em>action</em></strong> in Rails framework. I am going to name this method as index. It means that this method will be related with index.html.erb file which is view file. So, the name of action which is a method in controller should be identical with the name of view file.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/410/1*KEdIHqcinN_q2qpKmzEIQQ.png" /></figure><p>In the index action, I will put all of data to posts variable which is instance variable using Post.all method as you see above. If I put data to instance variable of index method, it means that I can have access to this variable on the view file using same name.</p><p>And I will make two more actions in this controller to write data to database. I will name this action as ‘create’. This action is going to get requests from view file and write it into database. And then, Page will be redirected to the index page.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/587/1*BWOF_ongjfpRafRmKYuBIQ.png" /><figcaption>Action ‘create’ in controller class</figcaption></figure><p>As you see above code, I created an action named create. And I put parameter’s value to the each variable using params keyword and create a line of record using <strong>‘Post.create’ method</strong>. After then, This page is redirected to the index page using ‘redirect_to’ keyword. After then, I will make an empty action named ‘new’ for a page to input data.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/274/1*r-CI-y4UojAsY-i_hINibg.png" /><figcaption>Action ‘new’ in controller class</figcaption></figure><p>Now, we have to create view files for actions in this controller. As I mentioned when I create controller I will name those view files same as the name of actions. First, I will create a view file for index action. Move to the post folder and created a <strong>“index.html.erb”</strong> file. In this file, I will write html codes to show the list of blog post using html.</p><pre>#index.html.erb<br>1 &lt;h1&gt;List&lt;/h1&gt;<br>2  &lt;table border=1&gt;<br>3   &lt;tr&gt;<br>4    &lt;th&gt;Num&lt;/th&gt;<br>5    &lt;th&gt;title&lt;/th&gt;<br>6    &lt;th&gt;wrtier&lt;/th&gt;<br>7    &lt;th&gt;content&lt;/th&gt;<br>8  &lt;/tr&gt;<br>9  &lt;% @posts.each do |p| %&gt;<br>10 &lt;tr&gt;<br>11  &lt;td&gt;&lt;%= p.id %&gt;&lt;/td&gt;<br>12  &lt;td&gt;&lt;%= p.title %&gt;&lt;/td&gt;<br>13  &lt;td&gt;&lt;%= p.writer %&gt;&lt;/td&gt;<br>14  &lt;td&gt;&lt;%= p.content %&gt;&lt;/td&gt;<br>15 &lt;/tr&gt;<br>16 &lt;% end %&gt;<br>17 &lt;/table&gt;<br>18 &lt;a href=&quot;/post/new&quot;&gt;Create new post&lt;/a&gt;</pre><p>It would not be difficult to understand this codes in html file except line 9. In the line 9, <strong>@posts.each do |p|</strong> means that it is looping objects in the instance variable(posts) and each object is put to the variable named p. In this loop, you can use the variable p to retrieve data and those values are printed out in the table. And I gave a link to direct this page to a new.html.erb to enter data.</p><pre>#new.html.erb<br>1 &lt;h1&gt;Create New Post&lt;/h1&gt;<br>2 &lt;form action=&quot;/post/create&quot;&gt;<br>3  &lt;input type=&quot;text&quot; name=&quot;writer&quot; placeholder=&quot;writer&quot;&gt;&lt;br&gt;<br>4  &lt;input type=&quot;text&quot; name=&quot;title&quot; placeholder=&quot;title&quot;&gt;&lt;br&gt;<br>5  &lt;textarea name=&quot;content&quot;&gt;&lt;/textarea&gt;&lt;br&gt;<br>6   &lt;input type=&quot;submit&quot;&gt;<br>7 &lt;/form&gt;</pre><p>I am using form tag to send data to ‘create’ action in the controller. This form tag will send requests to the create action as a GET request. As you see in the create action, requests are read from the params method. The params method is the object which represents the parameters (or fields) coming in from the form.</p><h3>3. Set routing paths for view and actions</h3><p>As we are done with creating views, controller and actions, the last thing we have to do is to set routing paths for view and actions in the controller. Open routes.rb file in config folder.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/777/1*sHxTcu9IVI0Tqe1lrk4-ew.png" /><figcaption>routes.rb</figcaption></figure><p>If you open this file, you can see the same screen with above image. In this file, you can see some examples for routing paths. As you see in the example, you have to specify path you are going to use for an action. For example, if you like to use path as ‘post/index’ and connect this path to ‘index’ action of control file, you can write like this below code.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/308/1*sMH961v5zA0RlJo_jjuNvw.png" /><figcaption>Routing the index action to the path</figcaption></figure><p>The first part before an arrow means the path and then the second part after an arrow means controller and action that will be connected with path. You also can specify the request method such as ‘get’ or ‘post’ in the beginning of routing rule.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/339/1*NDCoustUAYgCDI9p8mHS1A.png" /><figcaption>Set routing rules</figcaption></figure><p>As you see above, I set three routing paths for three actions in the controller. For the create action, we don’t have a view file, but this action is redirecting page to the view of index page. As all of settings is done, Let’s run this web application on rails server. Type rails server in the folder of project.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/377/1*_WGbdWXed6pFv_2m9RCVew.png" /><figcaption>index page</figcaption></figure><p>If you go to localhost:3000/post/index, you would see the list of data. And if you click the link, You will be brought to the input data page.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/430/1*bRwH0jX157wdv63xEnAmhQ.png" /><figcaption>input data page</figcaption></figure><p>And after you enter data in the form and submit it, data will be saved to database. And this page will be redirected to index page and you can see the data you entered on the list.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/433/1*EW_7EPPeLivL8cBjuddy_A.png" /><figcaption>Redirected page</figcaption></figure><h3>4. Use Scaffolding in Rails</h3><p>Rails scaffolding is a fast way to make key elements of your application. If you want to create models, views, and controllers using one line of command, scaffolding is a good choice. Scaffolding is generating all of steps that we have done before at once.</p><pre>$ rails generate scaffold Article writer:string title:string content:text</pre><p>Now, I generated an web application for articles by running above a line of command in the same project.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/719/1*ZpzD4KAoasijEwOeMEVbzA.png" /></figure><p>As you see in this screen, rails framework automatically generated files controller, view and model at once. If you go to localhost:3000/articles, you can see the index page.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/414/1*Qbk8pHneF1KL-N4q3BQl7w.png" /><figcaption>index page for article</figcaption></figure><p>If you click the link for new article, you will be brought to the page for new article.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/401/1*JMYNfNhWVZTvOSh7-0v_VQ.png" /><figcaption>input data page for new article</figcaption></figure><p>And when you enter data and submit it, you are able to see those data on the list such as below screenshot. Actually it is totally identical functionality that we have done in the previous steps!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/375/1*okZsbV7O0Da2L8j4m4NpMw.png" /><figcaption>Entered data is showing up on the list!</figcaption></figure><h3><strong>In Conclusion</strong></h3><p>Through this post, I have talked about how to build CRUD web application using rails framework. But I was talking some parts of CRUD application on creating and reading. However, for updating and deleting, it will be done as same way of functionality for creating and reading.</p><p>Also, we have seen how to use scaffolding to generate CRUD application that has same functionality at once! Actually I don’t recommend to use scaffolding because it is difficult to tweak the generated application by scaffolding if you don’t know well about structure of rails framework. But scaffolding can be helpful for developers who want to finish development fast.</p><p>I think that through this 4th blog post, you might feel why Ruby on rails has those advantages that I have mentioned in previous blog post. I agree one hundred percent with that advantages of Ruby on rails. This framework is very useful for developing back-end of web application very fast as you see here!</p><p>I have talked a lot of things about rails framework on this post. So you may feel it is too much to understand. However, I hope this blog post will help many people who read it to learn about Ruby on rails. Thank you.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=66e375d4aba9" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Part 3. Rails frameworks and Key Components]]></title>
            <link>https://medium.com/@jamesjeonggyukong/part-3-rails-frameworks-and-key-components-c0951835fe0d?source=rss-41741a38bbad------2</link>
            <guid isPermaLink="false">https://medium.com/p/c0951835fe0d</guid>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[ruby-on-rails]]></category>
            <dc:creator><![CDATA[James Jeonggyu Kong]]></dc:creator>
            <pubDate>Mon, 20 Mar 2017 01:32:03 GMT</pubDate>
            <atom:updated>2017-04-06T17:21:18.550Z</atom:updated>
            <content:encoded><![CDATA[<h3>Introduction</h3><p>For the previous two posts, I discussed about ruby language and basic syntax. However, you might not feel exactly how ruby language can be used for developing program such as web application. Therefore, in this post, I will talk about rails framework and key components.</p><h3>What is rails framework?</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/380/1*PKMmof2DJkNQh66eizd2Uw.png" /></figure><p>Rails is one of framework using ruby language to develop web application. Through rails framework, you can easily develop web application using tools that rails supports. In other words, you can think of it as a “bundle of code” that already has a robustly designed base skeleton so that someone can easily create a web service using Ruby language. Because of the fact that it works in the Ruby language, Rails is often referred to as Ruby on Rails.</p><h3>Why do we need to use Rails?</h3><p>In fact, you could make your Web service run by defining a server-wide mechanism for operation using only a programming language without a web framework. It is not impossible. However, it is followed by tremendous hardship to write codes for a program that receives and analyzes a request from a client (a web browser), a program that outputs a page requested by a client to a web browser screen and a program that searches the database for data requested by the client. You must write them by yourself without framework. In fact, it is so hard to write and it does not have to be as long as you fully understand how it works. That’s why we are using frameworks.</p><h3>Advantages of Rails</h3><h4>1. Faster development time lapse</h4><p>The greatest strength of Rails is that it greatly improves the speed of web service development. David Heinemeier Hansson (Danish DHH), the creator of Rails, says that the most important principle in Web service development is “COC(Convention over Configuration)” and “DRY(Do not Repeat Yourself). If you want to develop a web service using a common web framework, you have to go through a lot of configuration steps during the middle part of development. However, Rails does not care much about these minor settings in Web service development. By automatically applying conventionally used configuration settings to all web services, you do not have to spend unnecessary time in the configuration process. Because of this, developers using Rails can concentrate only on the functionality they want to implement, and do not have to repeat inefficient programming because of the small configuration.</p><h4>2. Flexibility</h4><p>Another strength of Rails is its high flexibility. In the case of a web framework with low flexibility, when a developer wants to make some modifications or add new functions to an existing web service, he or she has to deal with the whole project greatly. But with Rails’s unique flexibility, you can easily modify the parts of existing Web services that meet the changing needs of Web service users, and easily add new features.</p><h4><strong>3. </strong>Cost-effectiveness</h4><p>By using Rails to develop Web services and reducing the initial development and maintenance implementation time, it will speed up the development speed as mentioned above and also shorten development costs. In addition, as Ruby is an open source programming language, Rails is also an open source web framework. This means that the source code is fully public and is a free license web framework. Because of this, developing web services using Ruby and Rails can significantly reduce development costs compared to using non-open source technologies such as Java and .NET.</p><h3>Key components of Rails</h3><p>Rails is based on the Model-View-Controller (MVC) model. As you might know, the MVC model is a kind of design pattern that divides a web application into three components: a model, a view, and a controller, and assigns a unique role to each. In rails, concept of routes is added to those three components.</p><h4>1. Model</h4><p>A model is a component that deals with data. Models can be used to create new database tables in a database through DBMS (MySQL, MongoDB, SQLite, etc.), store new data in tables, read existing stored data, It is responsible for all tasks. In Rails, a device called Active Record soon becomes the model entity, and you can use the Active Record’s user-friendly commands to conveniently manipulate the DBMS.</p><h4>2. View</h4><p>A view is a component that deals directly with what is visible to users. In Rails, it is related with files such as html, CSS and JavaScript of web application. A view file has a different extension as .html.erb.</p><h4>3. Controller</h4><p>A controller is a component that controls the interaction between the model and the view. To help understand, I could say a controller in Rails is similar concept of Servlet class of web application. In other words, the controller receives the URL request from the client to display the web page. In the process, the controller requests data from the model to obtain the necessary data. When the model manipulates the DBMS to transmit the data to the controller, controller reflects this data in the view of the corresponding web page and provides it to the client side.</p><h4>4. Route</h4><p>When the controller accepts the client’s request, the process of routing is first intervened. The client sends a request to the server side in the form of a URL. The server specifies a route to match the controller method associated with the URL, and is also referred to as the word ‘routing’. do. In Rails, the routing rules are all defined in one particular Ruby file, and you will see them later in the course of your own hands-on practice.</p><h3>In conclusion</h3><p>For this blog, I have discussed about what Rails frameworks and which components will be used for this frameworks. For now, You might not understand how you could use this components for developing web application using Rails. On the next blog post, I will create simple web application using Rails framework. You will see how key elements are generated and working in Rails.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c0951835fe0d" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Part 2. Ruby on Rails and Basic syntax]]></title>
            <link>https://medium.com/@jamesjeonggyukong/part-2-ruby-on-rails-and-basic-syntax-6e7d366b355?source=rss-41741a38bbad------2</link>
            <guid isPermaLink="false">https://medium.com/p/6e7d366b355</guid>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[ruby-on-rails]]></category>
            <dc:creator><![CDATA[James Jeonggyu Kong]]></dc:creator>
            <pubDate>Sat, 18 Feb 2017 22:27:07 GMT</pubDate>
            <atom:updated>2020-09-08T00:06:53.036Z</atom:updated>
            <content:encoded><![CDATA[<p>On previous post, we finished to install Ruby on Rails on Ubuntu. But I did not mention about what Ruby On Rails is. It is because I am about to tell about it on this second post. On this post, I am going to deal with what Ruby On Rails is and Basic syntax of Ruby Language!</p><h3>What Is Ruby On Rails?</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/666/1*vxJYAIUGUbWLsGayGkHSnQ.png" /><figcaption>Literally Ruby On Rails!</figcaption></figure><p>As you see above picture, it is literally Ruby On Rails. I know it is not funny! But this picture actually is explaining well what ruby on rails. Becuase,</p><blockquote><strong>Ruby </strong>is one of the programming languages used on the server side. And <strong>Rails </strong>is a type of web framework that uses Ruby.</blockquote><p>It means that if you made a web application using ruby, You can run the program on Rails! Briefly saying, through rails, you could make web application with mvc model pattern such as controller, view, model classes that we have done in web application class before. Isn’t it exciting?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/350/1*sUL-IekSicd4MFkjov72vg.png" /><figcaption><strong>Creator. Yukihiro Matsumoto</strong></figcaption></figure><p>Yukihiro Matsumoto of Creator of Ruby says that he has created the ruby with the philosophy that</p><p>“Programming language should be designed closer to human than computer“ He also said,</p><p>“Sometimes people jot down pseudo-code on paper. If that pseudo-code runs directly on their computers, it’s best, isn’t it? Ruby tries to be like that, like pseudo-code that runs.”</p><p>As he said, he intended to create this language such as pseudo-code. It was his philosophy for developing ruby language. In Ruby language, there are some features unlike any other programming languages we have known.</p><p>One of feature is that this language is <strong>simple </strong>and <strong>intuitive </strong>language. As you see here, if you like to print simple “hello, world!” program in java, you should declare class and main method as you know.</p><pre><strong>class HelloWorld {<br>  public static void main(String [] args) {<br>    System.out.println(&quot;Hello World!&quot;);<br>  }<br>}</strong></pre><p>However, in ruby, you just need to write one line of code to do same function like this.</p><pre><strong>puts &quot;Hello World!&quot;</strong></pre><p>Secondly, Ruby is an <strong>Object-Oriented Language</strong>. In Ruby everything is an object including simple numeric values and even nil(null). As you see below code, you can call any instance methods from integer value because it is an object In Ruby.</p><pre><strong>5.times {print &quot;Hello, world&quot;}</strong></pre><p>Lastly, Ruby is <strong>flexible </strong>and <strong>dynamic </strong>language. Ruby is a flexible language in terms of syntax. For example, even if an object of a class is instantiated, You can edit method of the object. You also don’t need to specify data type of variables. If you learn about basic syntax of Ruby, You will see why this language is flexible and dynamic.</p><h3>Basic Syntax of Ruby</h3><p>In Ruby language, even it says it is simple and easy language, there are lots of basic syntax we have to learn such as data type, definitions of class and methods and so on.</p><p>I will briefly talk about those syntax on this post, but it is not possible to deal with all of syntax of Ruby! Thus, I highly recommend to see this two websites in order to learn and practice Ruby more!</p><ul><li><a href="https://www.ruby-lang.org/">Ruby Programming Language</a></li><li><a href="http://tryruby.org/levels/1/challenges/0">Ruby Tutorial - Try Ruby</a></li></ul><h3>Data type</h3><p>In ruby, there are typically three types of data type.</p><ol><li><strong>number</strong></li><li><strong>String</strong></li><li><strong>Boolean</strong></li></ol><pre>&gt; number_of_student = 3 #number<br> =&gt; 3<br>&gt; name = &quot;James&quot; #String<br> =&gt; &quot;James&quot;<br>&gt; isMale = true #boolean<br>=&gt; true</pre><blockquote>So if you give any value to variable, the variable will find out data type depend on what value you gave. So you don’t need to specify data type as you do in java. As you see here, if you give a number to variable. Its data type is number.</blockquote><h3>Naming convention</h3><h4><strong>1. Local variables, method parameters, method names</strong></h4><p>: Start with a lowercase letter or an underscore</p><blockquote>i.e.) name, _26, fishAndChips</blockquote><h4>2. Global variable</h4><p>: Start with $</p><blockquote>i.e.) $plan, $CUSTOMER</blockquote><h4>3. Instance variable</h4><p>: Start with @</p><blockquote>i.e.) @name, @pw</blockquote><h4>4. Class variables</h4><p>:Start with @@ and should be initialized before using it</p><blockquote>i.e.) @@plays, @@count</blockquote><h4>5. Class name or Constants</h4><p>: Start with uppercase letter</p><blockquote>i.e.) Person, PI</blockquote><h3>Input and output</h3><h4>▪ Puts: print value and make new line</h4><pre><strong>&gt; puts &quot;Hello&quot;<br></strong>&quot;James&quot; =&gt; nil</pre><h4>▪ Print: print value and don’t make new line</h4><pre><strong>&gt; print &quot;Hello&quot;<br></strong>&quot;James&quot; #make new-line<br> =&gt; nil</pre><h4>▪ gets: get input from prompt</h4><pre><strong>&gt; input = gets.chomp.to_i</strong></pre><blockquote>chomp: Remove the portion corresponding to this ‘Enter’</blockquote><blockquote>to_i: convert input into integer value</blockquote><h3>Methods</h3><h4>▪ def: a reserved word for declaring a method</h4><pre><strong>def sum<br>  puts 3 + 4 <br>end<br>sum or sum()</strong></pre><blockquote>When you like to make one method, you can use ‘def’ keyword before name of method. and make a block using end keyword. In order to run method, just call name of method or using parenthesis.</blockquote><pre><strong>def sum(a,b)<br>  puts a + b<br>end<br>sum(4,5)</strong></pre><blockquote>But if you like to give parameters on method, use parenthesis and put parameter variables. and when you call it, you should call method with parameters.</blockquote><h3>Class</h3><h4>▪ Start with the “class” keyword</h4><h4>▪ The initialize method plays role like a constructor of Java</h4><h4>▪ Variables beginning with “@” are instance variables</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/374/1*8ij6pu0dyQuXYDozu858Ug.png" /><figcaption>Basic structure of Class</figcaption></figure><h4>▪ Variables starting with “@@” are class variables</h4><ul><li>Class variable: a shared variable between objects of one class</li></ul><h4>▪ At run-time, you can change the definition of a class</h4><p>(Member variables / methods can be added / deleted / redefined)</p><h4>▪ How to instantiate an object</h4><h4>– Without initializing, use “new” keyword</h4><pre><strong>person = Person.new</strong></pre><h4>– Call initialize with parameters if you have initialize method</h4><pre><strong>person = Person.new(“adam”, “password”)</strong></pre><h3>Conclusion</h3><p>As you see on this post, you could see that it is not too hard to learn Ruby language. But I didn’t deal with every syntax of ruby on this blog post at once. Therefore I recommend you to learn more about advanced feature of Ruby using tutorial websites.</p><h3>Coming up next</h3><p>On next blog post, I will talk about how we can create classes such as controller, view, model for developing a web application using rails framework. Thank you!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6e7d366b355" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Part1. Set up environments for Ruby on rails on Linux server]]></title>
            <link>https://medium.com/@jamesjeonggyukong/part1-set-up-environments-for-ruby-on-rails-on-linux-server-9e35d9d50306?source=rss-41741a38bbad------2</link>
            <guid isPermaLink="false">https://medium.com/p/9e35d9d50306</guid>
            <category><![CDATA[setup-environmnets]]></category>
            <category><![CDATA[ruby-on-rails]]></category>
            <category><![CDATA[ruby]]></category>
            <dc:creator><![CDATA[James Jeonggyu Kong]]></dc:creator>
            <pubDate>Wed, 18 Jan 2017 06:01:36 GMT</pubDate>
            <atom:updated>2017-04-06T17:21:33.766Z</atom:updated>
            <content:encoded><![CDATA[<p>Hi guys, welcome to my blog for ruby on rails. I am pleasure to talk with you guys about ruby on rails. Before I talk about detail of Ruby on Rails, let’s start with building a development environment.</p><p>To install ruby and rails on your laptop, I am going to use Ubuntu Linux that is used in OS course. If you don’t want to use it for Ruby on rails, I am welcome to use any version of Linux, but I recommend to use Ubuntu or Debian Linux. This is because the installation commands may differ depending on the operating system. As a prerequisite, you need to have a basic knowledge of the Linux operating system, such as how to use basic commands and how to use the vi editor.</p><h3><strong>1.1 Installing Ruby on Ubuntu Linux</strong></h3><p>First, let’s proceed with installing Ruby assuming everyone is using the Ubuntu Linux operating system. To install Ruby on Rails, you need to install a manager program called RVM first. The Ruby Version Manager (RVM) is a service that makes it easy to install Ruby. This RVM is a program that simplifies the installation process of Ruby, and also makes it possible to manage multiple versions of Ruby simultaneously. To install Ruby easily, you need to install RVM first. After running Chrome, you can browse RVM in Google or go to the following link: <a href="https://rvm.io/"><strong>https://rvm.io</strong></a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*oXOuKMhnMihptRTTVJbbKw.png" /><figcaption>Copy the link of the red box!</figcaption></figure><p>The same screen as the above screen shot will appear. You must copy the commands in the red box to the screenshot.</p><pre>$ \curl -sSL https://get.rvm.io | bash -s stable</pre><p>However, If you try to use this command, the following error occurs. This is because we do not have a program to run curl on Linux.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/707/1*QboSir52FBmuoRMLWFWWbw.png" /><figcaption>Errors!</figcaption></figure><p>Do not panic, the following command will install the curl program.</p><pre>$ sudo apt-get update<br>$ sudo apt-get install curl</pre><p>Then, If you run the previous command after installing curl, as shown in the figure below, a brilliant message pops up and RVM installation is completed.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/742/1*Krqm3h74OWTQ7FQdJtdxoA.png" /><figcaption>Done with Installing RVM!</figcaption></figure><p>Then type the following on the terminal and press Enter:</p><pre>$ source .bash_profile</pre><p>Now it is time to install Ruby in earnest using RVM. On the terminal, type the following and press Enter:</p><pre>$ rvm install 2.0.0</pre><p>It means I will install Ruby 2.0.0. This will start the installation with a more brilliant screen as shown below. It will take some time to complete the installation, so let’s wait:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/744/1*gAR9s6y7btmzHSHnVbGaJw.png" /><figcaption>Check the complete message :)</figcaption></figure><p>To verify that Ruby is installed correctly, type the following command and press Enter:</p><pre>$ ruby -v</pre><p>It is a command to check the installed version of Ruby. If it comes out as shown below, it is properly installed!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/501/1*u2dmb2rG5RLmTQJDblkcQw.png" /><figcaption>You must see this message to verify installation</figcaption></figure><h3>1.2 Installing Rails on Ubuntu Linux</h3><p>Now that you’ve installed Ruby, it’s time to install Rails. Rails is the most widely used server framework based on the Ruby language.</p><p>To install Rails, type the following on the terminal and press Enter:</p><pre>$ gem install rails --version 4.0.1 --no-ri --no-rdoc</pre><p>It means I will install version 4.0.1 of Rails. That — no-ri — no-rdoc suffixed is meaning that they would not install various manuals and documents related to Rails. This will speed up the installation of Rails. At first, it seems like no message appears, but you have to wait with faith.</p><p>If you see ‘Successfully installed rails-4.0.1’ at the end of the screen as shown below, you have successfully completed the installation.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/569/1*KaZOGvheBnEQuPlKL2tzGg.png" /></figure><p>To verify that Rails is properly installed, type the following command and press Enter:</p><pre>$ rails -v</pre><p>It is a command to check the version of installed Rails. If it comes out as shown below, it is properly installed:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/336/1*vhpJS6YxC7SESsNfu_7eBw.png" /><figcaption>Done with installing rails framework!</figcaption></figure><h3>1.3 Creating a Rails project and running the server</h3><p>To test whether Rails works properly, I will create a Rails project. The ‘project’ here is the unit of the web service that you will be building in the future.</p><p>To create a new Rails project first, type the following on the terminal and press Enter:</p><pre>$ rails new project1 --skip-bundle</pre><p>This will create a new Rails project directory as shown below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/572/1*bpbzOnpBy9VQbz-CY8_4QA.png" /></figure><p>Enter the project directory you just created:</p><pre>$ cd project1</pre><p>Next, you need to add some content to a file named Gemfile in the current project directory. On the terminal, type the following and press Enter:</p><pre>$ echo &quot;gem &#39;therubyracer&#39;&quot; &gt;&gt; Gemfile</pre><p>The meaning of this command will be explained in another post. Next, type the following on the current project directory and press Enter.</p><pre>$ bundle install</pre><p>If the command is executed normally, you can see ‘Bundle completed!’ Message at the end of the screen as shown below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/622/1*H8twxC_0RLSSGRbMxQnp2g.png" /><figcaption>Bundle complete!</figcaption></figure><h3><em>Note</em></h3><blockquote><em>If you have any error while installing bundle, you should try this code:</em></blockquote><blockquote><em>sudo apt-get install g++</em></blockquote><blockquote><em>And try bundle install again. It will be solution for this problem.</em></blockquote><p>Now it is time to run the server properly. So far, the process of connecting to the server and making a series of settings has been a preparation for running the server. From the moment you start the server on the project directory, it receives the client’s request and delivers the service you created to the client.</p><p>To run the server, type the following command in the current project directory and press Enter.</p><pre>$ rails s</pre><p>The server is started for the project by rails s command. At this time, the server automatically exchanges requests with the client through port 3000. If the server is running normally, you can see the message shown below</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/734/1*bGsGLlgyNBd2p3hu8HWwdQ.png" /></figure><p>Now run Browser, type ‘localhost: 3000’ in the address bar and hit enter. If the screen shown below is successful, All of setting is done successfully.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*sTapfSE_LjpybaPSeC-9qQ.png" /><figcaption>Setting is done!</figcaption></figure><p>If you want to stop running the server, press Ctrl + c in this state. Then the server will stop running with the following message:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/545/1*V4VN55-gUF1sb6_ST_TTjQ.png" /><figcaption>Stop running server</figcaption></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9e35d9d50306" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>