<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Budh Ram Gurung</title>
    <description>The latest articles on DEV Community by Budh Ram Gurung (@dhanu).</description>
    <link>https://dev.to/dhanu</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F167279%2Fb00bdfb3-a2c9-426c-97a4-b835bbd134e2.jpg</url>
      <title>DEV Community: Budh Ram Gurung</title>
      <link>https://dev.to/dhanu</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/dhanu"/>
    <language>en</language>
    <item>
      <title>Simple voting web app in Sinatra</title>
      <dc:creator>Budh Ram Gurung</dc:creator>
      <pubDate>Tue, 13 Oct 2020 07:38:21 +0000</pubDate>
      <link>https://dev.to/dhanu/simple-voting-web-app-in-sinatra-2072</link>
      <guid>https://dev.to/dhanu/simple-voting-web-app-in-sinatra-2072</guid>
      <description>&lt;p&gt;In this tutorial, we are going to build a simple Voting web application using Sinatra.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;NOTE:&lt;/strong&gt; Source code included. See &lt;strong&gt;Resources&lt;/strong&gt; section.&lt;/p&gt;

&lt;h2&gt;
  
  
  Demo
&lt;/h2&gt;

&lt;p&gt;&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/yZYH4RXT0X0"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;h2&gt;
  
  
  Prerequisites
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Enthusiasm and passion to Learn&lt;/li&gt;
&lt;li&gt;Basic knowledge of HTML and CSS&lt;/li&gt;
&lt;li&gt;Basic knowledge of Ruby language&lt;/li&gt;
&lt;li&gt;Basic knowledge of &lt;a href="http://sinatrarb.com" rel="noopener noreferrer"&gt;Sinatra&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Inspiration for the tutorial
&lt;/h2&gt;

&lt;p&gt;The idea and content of this tutorial has been inspired by the&lt;br&gt;
&lt;a href="https://guides.railsgirls.com/sinatra-app" rel="noopener noreferrer"&gt;Rails Guides - create your first voting app in Sinatra&lt;/a&gt;.&lt;br&gt;
I am presenting it in my own way with little or updated content.&lt;/p&gt;
&lt;h2&gt;
  
  
  What is Sinatra
&lt;/h2&gt;

&lt;p&gt;Even though this tutorial assumes that you already have some knowledge of Sinatra, we will go through few components which will be used to build this application.&lt;/p&gt;

&lt;p&gt;In a simplest form, Sinatra is a tiny web framework written in Ruby to create Web applications quickly.&lt;br&gt;
Visit &lt;a href="http://sinatrarb.com" rel="noopener noreferrer"&gt;sinatrarb.com&lt;/a&gt;.&lt;/p&gt;
&lt;h2&gt;
  
  
  Setup your tools
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;This tutorial assumes you have Ruby preinstalled else consider checking &lt;a href="https://dev.to/ruby/section-one/getting-started/"&gt;getting started with Ruby&lt;/a&gt; to install Ruby in your system.&lt;/li&gt;
&lt;li&gt;First we need to install the web framework in our system. Run the following command to install Sinatra into the system:
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;  &lt;span class="nv"&gt;$ &lt;/span&gt;gem &lt;span class="nb"&gt;install &lt;/span&gt;sinatra &lt;span class="nt"&gt;--no-document&lt;/span&gt;
  Successfully installed sinatra-2.1.0
  1 gem installed
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;&lt;strong&gt;NOTE:&lt;/strong&gt; The flag &lt;code&gt;--no-document&lt;/code&gt; will help to speed up the installation to gem by not installing the documentation. If you want documentation of the Sinatra gem too, consider removing it from the above command.&lt;/p&gt;
&lt;h2&gt;
  
  
  Basic app setup
&lt;/h2&gt;

&lt;p&gt;Let's first create a project folder with name as &lt;code&gt;voting_app&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="nb"&gt;mkdir &lt;/span&gt;voting_app
&lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="nb"&gt;cd &lt;/span&gt;voting_app
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then, create a file named &lt;code&gt;voting.rb&lt;/code&gt; with following content:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="nb"&gt;require&lt;/span&gt; &lt;span class="s1"&gt;'sinatra'&lt;/span&gt;

&lt;span class="n"&gt;get&lt;/span&gt; &lt;span class="s1"&gt;'/'&lt;/span&gt; &lt;span class="k"&gt;do&lt;/span&gt;
  &lt;span class="s1"&gt;'Hello, voter!'&lt;/span&gt;
&lt;span class="k"&gt;end&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Run your app
&lt;/h2&gt;

&lt;p&gt;Rechecking our location of project which is&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="nb"&gt;pwd&lt;/span&gt;
/some/user/voting_app/

&lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="nb"&gt;ls
&lt;/span&gt;voting.rb
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now, run the app by running the command as:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;ruby voting.rb
&lt;span class="o"&gt;==&lt;/span&gt; Sinatra &lt;span class="o"&gt;(&lt;/span&gt;v2.1.0&lt;span class="o"&gt;)&lt;/span&gt; has taken the stage on 4567 &lt;span class="k"&gt;for &lt;/span&gt;development with backup from Thin
Thin web server &lt;span class="o"&gt;(&lt;/span&gt;v1.7.2 codename Bachmanity&lt;span class="o"&gt;)&lt;/span&gt;
Maximum connections &lt;span class="nb"&gt;set &lt;/span&gt;to 1024
Listening on localhost:4567, CTRL+C to stop
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now, open the url &lt;a href="http://localhost:4567" rel="noopener noreferrer"&gt;http://localhost:4567&lt;/a&gt; in your browser to see your app.&lt;/p&gt;

&lt;p&gt;You should see a web page with &lt;code&gt;Hello, voter!&lt;/code&gt; as it's content.&lt;/p&gt;

&lt;h2&gt;
  
  
  Code explanation
&lt;/h2&gt;

&lt;p&gt;The way to define route in Sinatra is to write a HTTP method paired with URL-matching pattern. Each route is associated with a block:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="n"&gt;get&lt;/span&gt; &lt;span class="s1"&gt;'/'&lt;/span&gt; &lt;span class="k"&gt;do&lt;/span&gt;
  &lt;span class="c1"&gt;# code&lt;/span&gt;
&lt;span class="k"&gt;end&lt;/span&gt;

&lt;span class="n"&gt;post&lt;/span&gt; &lt;span class="s1"&gt;'/'&lt;/span&gt; &lt;span class="k"&gt;do&lt;/span&gt;
  &lt;span class="c1"&gt;# code&lt;/span&gt;
&lt;span class="k"&gt;end&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Check the &lt;a href="https://github.com/sinatra/sinatra#routes" rel="noopener noreferrer"&gt;Sinatra#routes&lt;/a&gt; to get more details.&lt;/p&gt;

&lt;p&gt;In the above step, we have defined a &lt;code&gt;GET&lt;/code&gt; route for our root URL (&lt;code&gt;/&lt;/code&gt;) and inside it we are just return a string.&lt;/p&gt;

&lt;p&gt;Simple enough so far.&lt;/p&gt;

&lt;h2&gt;
  
  
  HTML response
&lt;/h2&gt;

&lt;p&gt;Let's update our implementation above to return HTML content instead of text.&lt;/p&gt;

&lt;p&gt;Update the &lt;code&gt;get '/'&lt;/code&gt; implementation as:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="n"&gt;get&lt;/span&gt; &lt;span class="s1"&gt;'/'&lt;/span&gt; &lt;span class="k"&gt;do&lt;/span&gt;
  &lt;span class="s1"&gt;'&amp;lt;h1&amp;gt;Hello, voter!&amp;lt;/h1&amp;gt;'&lt;/span&gt;
&lt;span class="k"&gt;end&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now, if you restart the app (&lt;code&gt;Ctrl+C&lt;/code&gt; to stop the existing server and then run &lt;code&gt;ruby voting.rb&lt;/code&gt;), you will see &lt;code&gt;Hello, voter!&lt;/code&gt; in heading H1 format in the browser.&lt;/p&gt;

&lt;h2&gt;
  
  
  Adding View index
&lt;/h2&gt;

&lt;p&gt;Now, if you are seeing above, then the HTML part might be too tricky to handle if the response we want to send is complex.&lt;/p&gt;

&lt;p&gt;One of the way to handle displaying content is through &lt;code&gt;View&lt;/code&gt; which is a component or part of web application which handles displaying the content.&lt;/p&gt;

&lt;p&gt;To ease of management, let's create a folder with name &lt;code&gt;views&lt;/code&gt; and write our content for our root URL (&lt;code&gt;/&lt;/code&gt;) into &lt;code&gt;index.erb&lt;/code&gt; file.&lt;/p&gt;

&lt;p&gt;The content for &lt;code&gt;index.erb&lt;/code&gt; file is as follows:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="cp"&gt;&amp;lt;!DOCTYPE html&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;html&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;head&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;meta&lt;/span&gt; &lt;span class="na"&gt;charset=&lt;/span&gt;&lt;span class="s"&gt;'UTF-8'&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;title&amp;gt;&lt;/span&gt;Voting App&lt;span class="nt"&gt;&amp;lt;/title&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;/head&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;body&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;h2&amp;gt;&lt;/span&gt;What's for dinner?&lt;span class="nt"&gt;&amp;lt;/h2&amp;gt;&lt;/span&gt;

    &lt;span class="nt"&gt;&amp;lt;form&lt;/span&gt; &lt;span class="na"&gt;action=&lt;/span&gt;&lt;span class="s"&gt;'cast'&lt;/span&gt; &lt;span class="na"&gt;method=&lt;/span&gt;&lt;span class="s"&gt;'post'&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="nt"&gt;&amp;lt;ul&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;&lt;/span&gt;&lt;span class="err"&gt;%&lt;/span&gt; &lt;span class="na"&gt;CHOICES.each&lt;/span&gt; &lt;span class="na"&gt;do&lt;/span&gt; &lt;span class="err"&gt;|&lt;/span&gt;&lt;span class="na"&gt;id&lt;/span&gt;&lt;span class="err"&gt;,&lt;/span&gt; &lt;span class="na"&gt;text&lt;/span&gt;&lt;span class="err"&gt;|&lt;/span&gt; &lt;span class="err"&gt;%&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
          &lt;span class="nt"&gt;&amp;lt;li&amp;gt;&lt;/span&gt;
            &lt;span class="nt"&gt;&amp;lt;label&amp;gt;&lt;/span&gt;
              &lt;span class="nt"&gt;&amp;lt;input&lt;/span&gt; &lt;span class="na"&gt;type=&lt;/span&gt;&lt;span class="s"&gt;'radio'&lt;/span&gt; &lt;span class="na"&gt;name=&lt;/span&gt;&lt;span class="s"&gt;'vote'&lt;/span&gt; &lt;span class="na"&gt;value=&lt;/span&gt;&lt;span class="s"&gt;'&amp;lt;%= id %&amp;gt;'&lt;/span&gt; &lt;span class="na"&gt;id=&lt;/span&gt;&lt;span class="s"&gt;'vote_&amp;lt;%= id %&amp;gt;'&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
              &lt;span class="nt"&gt;&amp;lt;&lt;/span&gt;&lt;span class="err"&gt;%=&lt;/span&gt; &lt;span class="na"&gt;text&lt;/span&gt; &lt;span class="err"&gt;%&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
            &lt;span class="nt"&gt;&amp;lt;/label&amp;gt;&lt;/span&gt;
          &lt;span class="nt"&gt;&amp;lt;/li&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;&lt;/span&gt;&lt;span class="err"&gt;%&lt;/span&gt; &lt;span class="na"&gt;end&lt;/span&gt; &lt;span class="err"&gt;%&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="nt"&gt;&amp;lt;/ul&amp;gt;&lt;/span&gt;

      &lt;span class="nt"&gt;&amp;lt;button&lt;/span&gt; &lt;span class="na"&gt;type=&lt;/span&gt;&lt;span class="s"&gt;'submit'&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Cast this vote!&lt;span class="nt"&gt;&amp;lt;/button&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;/form&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;/body&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/html&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And, add following dummy data for our list of voting options in &lt;code&gt;voting.rb&lt;/code&gt; file as:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="no"&gt;CHOICES&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="s1"&gt;'HAM'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="s1"&gt;'Hamburger'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="s1"&gt;'PIZ'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="s1"&gt;'Pizza'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="s1"&gt;'CUR'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="s1"&gt;'Curry'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="s1"&gt;'NOO'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="s1"&gt;'Noodles'&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="n"&gt;get&lt;/span&gt; &lt;span class="s1"&gt;'/'&lt;/span&gt; &lt;span class="k"&gt;do&lt;/span&gt;
 &lt;span class="o"&gt;...&lt;/span&gt;
&lt;span class="k"&gt;end&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;After restarting the server, the web page will now show the following:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fbrgtrainings.com%2Fassets%2Fimg%2Ftutorials%2Fvoting-app%2F1.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fbrgtrainings.com%2Fassets%2Fimg%2Ftutorials%2Fvoting-app%2F1.png" alt="Preview 1"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Code explanation
&lt;/h2&gt;

&lt;p&gt;You might be wondering how about code is working. Right?&lt;/p&gt;

&lt;p&gt;It is quite easy to understand. Just think the whole files including &lt;code&gt;voting.rb&lt;/code&gt; or any erb files as part of one system.&lt;/p&gt;

&lt;p&gt;Now, we have defined a constant &lt;code&gt;CHOICES&lt;/code&gt; which is a global constant and available to all the Ruby files including erb files.&lt;/p&gt;

&lt;p&gt;Hence, in the &lt;code&gt;index.erb&lt;/code&gt; file we are able to access it.&lt;/p&gt;

&lt;p&gt;Considering the following code snippet:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight erb"&gt;&lt;code&gt;&lt;span class="cp"&gt;&amp;lt;%&lt;/span&gt; &lt;span class="no"&gt;CHOICES&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;each&lt;/span&gt; &lt;span class="k"&gt;do&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt;&lt;span class="nb"&gt;id&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;text&lt;/span&gt;&lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="cp"&gt;%&amp;gt;&lt;/span&gt;
  ...
  &lt;span class="nt"&gt;&amp;lt;input&lt;/span&gt; &lt;span class="na"&gt;type=&lt;/span&gt;&lt;span class="s"&gt;'radio'&lt;/span&gt; &lt;span class="na"&gt;name=&lt;/span&gt;&lt;span class="s"&gt;'vote'&lt;/span&gt; &lt;span class="na"&gt;value=&lt;/span&gt;&lt;span class="s"&gt;'&lt;/span&gt;&lt;span class="cp"&gt;&amp;lt;%=&lt;/span&gt; &lt;span class="nb"&gt;id&lt;/span&gt; &lt;span class="cp"&gt;%&amp;gt;&lt;/span&gt;&lt;span class="s"&gt;'&lt;/span&gt; &lt;span class="na"&gt;id=&lt;/span&gt;&lt;span class="s"&gt;'vote_&lt;/span&gt;&lt;span class="cp"&gt;&amp;lt;%=&lt;/span&gt; &lt;span class="nb"&gt;id&lt;/span&gt; &lt;span class="cp"&gt;%&amp;gt;&lt;/span&gt;&lt;span class="s"&gt;'&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
  &lt;span class="cp"&gt;&amp;lt;%=&lt;/span&gt; &lt;span class="n"&gt;text&lt;/span&gt; &lt;span class="cp"&gt;%&amp;gt;&lt;/span&gt;
  ...
&lt;span class="cp"&gt;&amp;lt;%&lt;/span&gt; &lt;span class="k"&gt;end&lt;/span&gt; &lt;span class="cp"&gt;%&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The ERB tag &lt;code&gt;&amp;lt;% ... %&amp;gt;&lt;/code&gt; is used to perform execution of Ruby code. Here it is performing &lt;code&gt;each&lt;/code&gt; iteration.&lt;br&gt;
And, tag &lt;code&gt;&amp;lt;%= ... %&amp;gt;&lt;/code&gt; is used to execute the Ruby code and replace the tag with evaluated results.&lt;/p&gt;

&lt;p&gt;Hence, the above code will generate following HTML content:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;li&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;label&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;input&lt;/span&gt; &lt;span class="na"&gt;type=&lt;/span&gt;&lt;span class="s"&gt;"radio"&lt;/span&gt; &lt;span class="na"&gt;name=&lt;/span&gt;&lt;span class="s"&gt;"vote"&lt;/span&gt; &lt;span class="na"&gt;value=&lt;/span&gt;&lt;span class="s"&gt;"HAM"&lt;/span&gt; &lt;span class="na"&gt;id=&lt;/span&gt;&lt;span class="s"&gt;"vote_HAM"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
    Hamburger
  &lt;span class="nt"&gt;&amp;lt;/label&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/li&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;li&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;label&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;input&lt;/span&gt; &lt;span class="na"&gt;type=&lt;/span&gt;&lt;span class="s"&gt;"radio"&lt;/span&gt; &lt;span class="na"&gt;name=&lt;/span&gt;&lt;span class="s"&gt;"vote"&lt;/span&gt; &lt;span class="na"&gt;value=&lt;/span&gt;&lt;span class="s"&gt;"PIZ"&lt;/span&gt; &lt;span class="na"&gt;id=&lt;/span&gt;&lt;span class="s"&gt;"vote_PIZ"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
    Pizza
  &lt;span class="nt"&gt;&amp;lt;/label&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/li&amp;gt;&lt;/span&gt;
...
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;See &lt;a href="https://webapps-for-beginners.rubymonstas.org/erb/erb_templates.html" rel="noopener noreferrer"&gt;ERB Templates&lt;/a&gt; for more.&lt;/p&gt;

&lt;h2&gt;
  
  
  Adding the CSS
&lt;/h2&gt;

&lt;p&gt;Currently, our page looks ugly. We need to add CSS to make it enough beautiful which makes our eyes little happy.&lt;/p&gt;

&lt;p&gt;Sinatra assumes that you should store all your static files like CSS, JS or images under &lt;code&gt;public&lt;/code&gt; folder.&lt;br&gt;
See &lt;a href="https://github.com/sinatra/sinatra#static-files" rel="noopener noreferrer"&gt;static files&lt;/a&gt; for more details.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;While including the static file in the view files, you don't add 'public' in the path. Hence, if you store your CSS inside 'public/css/style.css' then while linking the CSS inside view file, you just write '/css/style.css' as path.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Create a folder with name &lt;code&gt;public&lt;/code&gt; and then create another folder with name &lt;code&gt;css&lt;/code&gt; to store CSS specific files. Then, finally create a CSS file with name &lt;code&gt;style.css&lt;/code&gt;. Add following content inside the &lt;code&gt;style.css&lt;/code&gt; file to have minimum styling to our existing app.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nc"&gt;.container&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;margin&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;auto&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;max-width&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;1100px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;padding&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;0&lt;/span&gt; &lt;span class="m"&gt;20px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nt"&gt;form&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;background&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;#eee&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;width&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;450px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;padding&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;1rem&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="nt"&gt;ul&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;list-style&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;none&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;margin&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;padding&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="nt"&gt;button&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;margin-top&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;10px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fbrgtrainings.com%2Fassets%2Fimg%2Ftutorials%2Fvoting-app%2F2.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fbrgtrainings.com%2Fassets%2Fimg%2Ftutorials%2Fvoting-app%2F2.png" alt="Preview 2"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Passing data to View
&lt;/h2&gt;

&lt;p&gt;Let's add the main title for the page. Update the &lt;code&gt;index.erb&lt;/code&gt; file with following content:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight erb"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;body&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;'container'&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;h1&amp;gt;&lt;/span&gt;&lt;span class="cp"&gt;&amp;lt;%=&lt;/span&gt; &lt;span class="vi"&gt;@title&lt;/span&gt; &lt;span class="cp"&gt;%&amp;gt;&lt;/span&gt;&lt;span class="nt"&gt;&amp;lt;/h1&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;p&amp;gt;&lt;/span&gt;What's for dinner?&lt;span class="nt"&gt;&amp;lt;/p&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And, change the &lt;code&gt;get&lt;/code&gt; action as:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="n"&gt;get&lt;/span&gt; &lt;span class="s1"&gt;'/'&lt;/span&gt; &lt;span class="k"&gt;do&lt;/span&gt;
  &lt;span class="vi"&gt;@title&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;'Welcome to the Foo Restaurant!'&lt;/span&gt;
  &lt;span class="n"&gt;erb&lt;/span&gt; &lt;span class="ss"&gt;:index&lt;/span&gt;
&lt;span class="k"&gt;end&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We are able to do this as templates in Sinatra are evaluated within the same context as route handlers like &lt;code&gt;get&lt;/code&gt;.&lt;br&gt;
Instance variables set in route handlers are directly accessible by templates.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fbrgtrainings.com%2Fassets%2Fimg%2Ftutorials%2Fvoting-app%2F3.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fbrgtrainings.com%2Fassets%2Fimg%2Ftutorials%2Fvoting-app%2F3.png" alt="Preview 3"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  Ability to cast Vote (POST results)
&lt;/h2&gt;

&lt;p&gt;Let's add an ability to cast vote.&lt;/p&gt;

&lt;p&gt;Add following action into &lt;code&gt;voting.rb&lt;/code&gt; file:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="n"&gt;post&lt;/span&gt; &lt;span class="s1"&gt;'/cast'&lt;/span&gt; &lt;span class="k"&gt;do&lt;/span&gt;
  &lt;span class="vi"&gt;@title&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;'Thanks for casting your vote!'&lt;/span&gt;
  &lt;span class="vi"&gt;@vote&lt;/span&gt;  &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;params&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'vote'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
  &lt;span class="n"&gt;erb&lt;/span&gt; &lt;span class="ss"&gt;:cast&lt;/span&gt;
&lt;span class="k"&gt;end&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Also, create a new file &lt;code&gt;cast.erb&lt;/code&gt; in the &lt;code&gt;views&lt;/code&gt; directory and put following code:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight erb"&gt;&lt;code&gt;&lt;span class="cp"&gt;&amp;lt;!DOCTYPE html&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;html&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;head&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;meta&lt;/span&gt; &lt;span class="na"&gt;charset=&lt;/span&gt;&lt;span class="s"&gt;'UTF-8'&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;title&amp;gt;&lt;/span&gt;Voting App&lt;span class="nt"&gt;&amp;lt;/title&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;link&lt;/span&gt; &lt;span class="na"&gt;rel=&lt;/span&gt;&lt;span class="s"&gt;"stylesheet"&lt;/span&gt; &lt;span class="na"&gt;href=&lt;/span&gt;&lt;span class="s"&gt;"css/style.css"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;/head&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;body&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;h1&amp;gt;&lt;/span&gt;&lt;span class="cp"&gt;&amp;lt;%=&lt;/span&gt; &lt;span class="vi"&gt;@title&lt;/span&gt; &lt;span class="cp"&gt;%&amp;gt;&lt;/span&gt;&lt;span class="nt"&gt;&amp;lt;/h1&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;p&amp;gt;&lt;/span&gt;You cast: &lt;span class="cp"&gt;&amp;lt;%=&lt;/span&gt; &lt;span class="no"&gt;CHOICES&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="vi"&gt;@vote&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="cp"&gt;%&amp;gt;&lt;/span&gt;&lt;span class="nt"&gt;&amp;lt;/p&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;p&amp;gt;&amp;lt;a&lt;/span&gt; &lt;span class="na"&gt;href=&lt;/span&gt;&lt;span class="s"&gt;'/results'&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;See the results!&lt;span class="nt"&gt;&amp;lt;/a&amp;gt;&amp;lt;/p&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;/body&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/html&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now, restart the server and open &lt;code&gt;https://loclhost:4567&lt;/code&gt; and choose the item for the dinner and click on &lt;code&gt;Cast this vote!&lt;/code&gt; button.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fbrgtrainings.com%2Fassets%2Fimg%2Ftutorials%2Fvoting-app%2F4.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fbrgtrainings.com%2Fassets%2Fimg%2Ftutorials%2Fvoting-app%2F4.png" alt="Preview 4"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Code explanation
&lt;/h2&gt;

&lt;p&gt;In the above we defined a new route &lt;code&gt;post '/cast'&lt;/code&gt; to handle any post request who target url is &lt;code&gt;/cast&lt;/code&gt;. Notice our &lt;code&gt;index.erb&lt;/code&gt; for the same:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight erb"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;form&lt;/span&gt; &lt;span class="na"&gt;action=&lt;/span&gt;&lt;span class="s"&gt;'cast'&lt;/span&gt; &lt;span class="na"&gt;method=&lt;/span&gt;&lt;span class="s"&gt;'post'&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
...
&lt;span class="nt"&gt;&amp;lt;/form&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now, when we submit the form by clicking on the &lt;code&gt;Cast the vote!&lt;/code&gt; button, then the form request is process by this &lt;code&gt;post&lt;/code&gt; route handler at the server end.&lt;/p&gt;

&lt;p&gt;Now, we have set the instance variables &lt;code&gt;@title&lt;/code&gt; and &lt;code&gt;@vote&lt;/code&gt; whose information can be displayed in the &lt;code&gt;/cast&lt;/code&gt; url through &lt;code&gt;cast.erb&lt;/code&gt; view template.&lt;/p&gt;

&lt;p&gt;Note that &lt;code&gt;@vote&lt;/code&gt; is set through &lt;code&gt;params&lt;/code&gt; which is of a request object which contains following when cast vote.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="s2"&gt;"vote"&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="s2"&gt;"NOO"&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;See &lt;a href="https://github.com/rack/rack/blob/master/lib/rack/request.rb" rel="noopener noreferrer"&gt;Rack::Request&lt;/a&gt; for in-depth information on &lt;code&gt;params&lt;/code&gt; object.&lt;/p&gt;

&lt;p&gt;Notice that this is actually the value of the radio button which we selected while voting.&lt;br&gt;
And, the value &lt;code&gt;NOO&lt;/code&gt; is coming as we had set the dummy values as:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="no"&gt;CHOICES&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="s1"&gt;'HAM'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="s1"&gt;'Hamburger'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="s1"&gt;'PIZ'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="s1"&gt;'Pizza'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="s1"&gt;'CUR'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="s1"&gt;'Curry'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="s1"&gt;'NOO'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="s1"&gt;'Noodles'&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Common layout
&lt;/h2&gt;

&lt;p&gt;If you notice both &lt;code&gt;index.erb&lt;/code&gt; and &lt;code&gt;cast.erb&lt;/code&gt; files, you will see some shared code. We can extract the shared code in Sinatra through &lt;em&gt;Layout&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;Create a layout file &lt;code&gt;layout.erb&lt;/code&gt; under &lt;code&gt;views&lt;/code&gt; directory and add the common HTML content from both which&lt;br&gt;
looks as follows:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight erb"&gt;&lt;code&gt;&lt;span class="cp"&gt;&amp;lt;!DOCTYPE html&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;html&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;head&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;meta&lt;/span&gt; &lt;span class="na"&gt;charset=&lt;/span&gt;&lt;span class="s"&gt;'UTF-8'&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;title&amp;gt;&lt;/span&gt;Voting App&lt;span class="nt"&gt;&amp;lt;/title&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;link&lt;/span&gt; &lt;span class="na"&gt;rel=&lt;/span&gt;&lt;span class="s"&gt;"stylesheet"&lt;/span&gt; &lt;span class="na"&gt;href=&lt;/span&gt;&lt;span class="s"&gt;"css/style.css"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;/head&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;body&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;h1&amp;gt;&lt;/span&gt;&lt;span class="cp"&gt;&amp;lt;%=&lt;/span&gt; &lt;span class="vi"&gt;@title&lt;/span&gt; &lt;span class="cp"&gt;%&amp;gt;&lt;/span&gt;&lt;span class="nt"&gt;&amp;lt;/h1&amp;gt;&lt;/span&gt;
    &lt;span class="cp"&gt;&amp;lt;%=&lt;/span&gt; &lt;span class="k"&gt;yield&lt;/span&gt; &lt;span class="cp"&gt;%&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;/body&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/html&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In general &lt;em&gt;Layout&lt;/em&gt; is used to define the HTML structure of the web page.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;In Sinatra, we deal with forms which is HTML fragments, not fully structured. Yield means that the layout should wait to the templates to render and then proceed. What happens is that the page is rendering the layout file then it stops when it hits the 'yield' statement and renders the associated template file. When the template is done, it keeps going to render everything else after the 'yield' statement in the layout. Therefore, it is very important to be cautious about choosing the right spot for yielding statement in your layout.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  Update the views files
&lt;/h2&gt;

&lt;p&gt;Update the views files &lt;code&gt;index.erb&lt;/code&gt; and &lt;code&gt;cast.erb&lt;/code&gt; as follows:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;index.erb&lt;/code&gt; file:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight erb"&gt;&lt;code&gt;  &lt;span class="c"&gt;&amp;lt;!-- Remove html, title and body tags --&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;p&amp;gt;&lt;/span&gt;What's for dinner?&lt;span class="nt"&gt;&amp;lt;/p&amp;gt;&lt;/span&gt;

  &lt;span class="nt"&gt;&amp;lt;form&lt;/span&gt; &lt;span class="na"&gt;action=&lt;/span&gt;&lt;span class="s"&gt;'cast'&lt;/span&gt; &lt;span class="na"&gt;method=&lt;/span&gt;&lt;span class="s"&gt;'post'&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;ul&amp;gt;&lt;/span&gt;
      &lt;span class="cp"&gt;&amp;lt;%&lt;/span&gt; &lt;span class="no"&gt;CHOICES&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;each&lt;/span&gt; &lt;span class="k"&gt;do&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt;&lt;span class="nb"&gt;id&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;text&lt;/span&gt;&lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="cp"&gt;%&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;li&amp;gt;&lt;/span&gt;
          &lt;span class="nt"&gt;&amp;lt;label&amp;gt;&lt;/span&gt;
            &lt;span class="nt"&gt;&amp;lt;input&lt;/span&gt; &lt;span class="na"&gt;type=&lt;/span&gt;&lt;span class="s"&gt;'radio'&lt;/span&gt; &lt;span class="na"&gt;name=&lt;/span&gt;&lt;span class="s"&gt;'vote'&lt;/span&gt; &lt;span class="na"&gt;value=&lt;/span&gt;&lt;span class="s"&gt;'&lt;/span&gt;&lt;span class="cp"&gt;&amp;lt;%=&lt;/span&gt; &lt;span class="nb"&gt;id&lt;/span&gt; &lt;span class="cp"&gt;%&amp;gt;&lt;/span&gt;&lt;span class="s"&gt;'&lt;/span&gt; &lt;span class="na"&gt;id=&lt;/span&gt;&lt;span class="s"&gt;'vote_&lt;/span&gt;&lt;span class="cp"&gt;&amp;lt;%=&lt;/span&gt; &lt;span class="nb"&gt;id&lt;/span&gt; &lt;span class="cp"&gt;%&amp;gt;&lt;/span&gt;&lt;span class="s"&gt;'&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
            &lt;span class="cp"&gt;&amp;lt;%=&lt;/span&gt; &lt;span class="n"&gt;text&lt;/span&gt; &lt;span class="cp"&gt;%&amp;gt;&lt;/span&gt;
          &lt;span class="nt"&gt;&amp;lt;/label&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;/li&amp;gt;&lt;/span&gt;
      &lt;span class="cp"&gt;&amp;lt;%&lt;/span&gt; &lt;span class="k"&gt;end&lt;/span&gt; &lt;span class="cp"&gt;%&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;/ul&amp;gt;&lt;/span&gt;

    &lt;span class="nt"&gt;&amp;lt;button&lt;/span&gt; &lt;span class="na"&gt;type=&lt;/span&gt;&lt;span class="s"&gt;'submit'&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Cast this vote!&lt;span class="nt"&gt;&amp;lt;/button&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;/form&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;cast.erb&lt;/code&gt; file:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight erb"&gt;&lt;code&gt;  &lt;span class="c"&gt;&amp;lt;!-- Remove html, title and body tags --&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;p&amp;gt;&lt;/span&gt;You cast: &lt;span class="cp"&gt;&amp;lt;%=&lt;/span&gt; &lt;span class="no"&gt;CHOICES&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="vi"&gt;@vote&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="cp"&gt;%&amp;gt;&lt;/span&gt;&lt;span class="nt"&gt;&amp;lt;/p&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;p&amp;gt;&amp;lt;a&lt;/span&gt; &lt;span class="na"&gt;href=&lt;/span&gt;&lt;span class="s"&gt;'/results'&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;See the results!&lt;span class="nt"&gt;&amp;lt;/a&amp;gt;&amp;lt;/p&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now, if you reload the web app (&lt;code&gt;https://localhost:4567&lt;/code&gt;) and cast the vote, you will get the same experience as before.&lt;/p&gt;

&lt;h2&gt;
  
  
  Add the results route and its view
&lt;/h2&gt;

&lt;p&gt;The final route is the result page (&lt;code&gt;/results&lt;/code&gt;) which you can see as a link in &lt;code&gt;/cast&lt;/code&gt; page.&lt;/p&gt;

&lt;p&gt;Add the following code into &lt;code&gt;voting.rb&lt;/code&gt; file:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="n"&gt;get&lt;/span&gt; &lt;span class="s1"&gt;'/results'&lt;/span&gt; &lt;span class="k"&gt;do&lt;/span&gt;
  &lt;span class="vi"&gt;@votes&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="s1"&gt;'HAM'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;7&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'PIZ'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'CUR'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="n"&gt;erb&lt;/span&gt; &lt;span class="ss"&gt;:results&lt;/span&gt;
&lt;span class="k"&gt;end&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here, we are creating dummy data &lt;code&gt;@votes&lt;/code&gt; which simulates the number of votes for a particular dish.&lt;/p&gt;

&lt;p&gt;Now, create its view file as &lt;code&gt;results.erb&lt;/code&gt; under &lt;code&gt;views&lt;/code&gt; directory.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight erb"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;h1&amp;gt;&lt;/span&gt;Voting Results&lt;span class="nt"&gt;&amp;lt;/h1&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;table&amp;gt;&lt;/span&gt;
  &lt;span class="cp"&gt;&amp;lt;%&lt;/span&gt; &lt;span class="no"&gt;CHOICES&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;each&lt;/span&gt; &lt;span class="k"&gt;do&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt;&lt;span class="nb"&gt;id&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;text&lt;/span&gt;&lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="cp"&gt;%&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;tr&amp;gt;&lt;/span&gt;
      &lt;span class="nt"&gt;&amp;lt;th&amp;gt;&lt;/span&gt;&lt;span class="cp"&gt;&amp;lt;%=&lt;/span&gt; &lt;span class="n"&gt;text&lt;/span&gt; &lt;span class="cp"&gt;%&amp;gt;&lt;/span&gt;&lt;span class="nt"&gt;&amp;lt;/th&amp;gt;&lt;/span&gt;
      &lt;span class="nt"&gt;&amp;lt;td&amp;gt;&lt;/span&gt;&lt;span class="cp"&gt;&amp;lt;%=&lt;/span&gt; &lt;span class="vi"&gt;@votes&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nb"&gt;id&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="cp"&gt;%&amp;gt;&lt;/span&gt;
      &lt;span class="nt"&gt;&amp;lt;td&amp;gt;&lt;/span&gt;&lt;span class="cp"&gt;&amp;lt;%=&lt;/span&gt; &lt;span class="s1"&gt;'#'&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="vi"&gt;@votes&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nb"&gt;id&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="cp"&gt;%&amp;gt;&lt;/span&gt;&lt;span class="nt"&gt;&amp;lt;/td&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;/tr&amp;gt;&lt;/span&gt;
  &lt;span class="cp"&gt;&amp;lt;%&lt;/span&gt; &lt;span class="k"&gt;end&lt;/span&gt; &lt;span class="cp"&gt;%&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/table&amp;gt;&lt;/span&gt;

&lt;span class="nt"&gt;&amp;lt;p&amp;gt;&amp;lt;a&lt;/span&gt; &lt;span class="na"&gt;href=&lt;/span&gt;&lt;span class="s"&gt;'/'&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Cast more votes!&lt;span class="nt"&gt;&amp;lt;/a&amp;gt;&amp;lt;/p&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now, check the results page after restarting the server (&lt;code&gt;Ctrl+c&lt;/code&gt; and run the app again). You will see the following similar page:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fbrgtrainings.com%2Fassets%2Fimg%2Ftutorials%2Fvoting-app%2F5.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fbrgtrainings.com%2Fassets%2Fimg%2Ftutorials%2Fvoting-app%2F5.png" alt="Preview 5"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Code explanation
&lt;/h2&gt;

&lt;p&gt;The &lt;code&gt;@votes&lt;/code&gt; is an instance variable which we had used to hold some dummy results at present.&lt;/p&gt;

&lt;p&gt;In the &lt;code&gt;results.erb&lt;/code&gt; page, &lt;code&gt;@votes[id]&lt;/code&gt; has been used to get the count for the particular dish. The code snippet &lt;code&gt;'#' * (@votes[id])&lt;/code&gt; basically print the symbol &lt;code&gt;#&lt;/code&gt; as many as vote count.&lt;/p&gt;

&lt;h2&gt;
  
  
  Persist the results using YAML::Store
&lt;/h2&gt;

&lt;p&gt;So far we have played with static dummy date.&lt;/p&gt;

&lt;p&gt;Let's store the voting done and update the count whenever we vote the specific dish.&lt;/p&gt;

&lt;p&gt;Add following code at the top of &lt;code&gt;voting.rb&lt;/code&gt; file:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="nb"&gt;require&lt;/span&gt; &lt;span class="s1"&gt;'yaml/store'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now, update the &lt;code&gt;post '/cast'&lt;/code&gt; and &lt;code&gt;get /results&lt;/code&gt; handlers:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="n"&gt;post&lt;/span&gt; &lt;span class="s1"&gt;'/cast'&lt;/span&gt; &lt;span class="k"&gt;do&lt;/span&gt;
  &lt;span class="vi"&gt;@title&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;'Thanks for casting your vote!'&lt;/span&gt;
  &lt;span class="vi"&gt;@vote&lt;/span&gt;  &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;params&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'vote'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;

  &lt;span class="c1"&gt;# create a votes.yml file and update the particular votes&lt;/span&gt;
  &lt;span class="vi"&gt;@store&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="no"&gt;YAML&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="no"&gt;Store&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;new&lt;/span&gt; &lt;span class="s1"&gt;'votes.yml'&lt;/span&gt;
  &lt;span class="vi"&gt;@store&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;transaction&lt;/span&gt; &lt;span class="k"&gt;do&lt;/span&gt;
    &lt;span class="vi"&gt;@store&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'votes'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;||=&lt;/span&gt; &lt;span class="p"&gt;{}&lt;/span&gt;
    &lt;span class="vi"&gt;@store&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'votes'&lt;/span&gt;&lt;span class="p"&gt;][&lt;/span&gt;&lt;span class="vi"&gt;@vote&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;||=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;
    &lt;span class="vi"&gt;@store&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'votes'&lt;/span&gt;&lt;span class="p"&gt;][&lt;/span&gt;&lt;span class="vi"&gt;@vote&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;+=&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;
  &lt;span class="k"&gt;end&lt;/span&gt;
  &lt;span class="n"&gt;erb&lt;/span&gt; &lt;span class="ss"&gt;:cast&lt;/span&gt;
&lt;span class="k"&gt;end&lt;/span&gt;

&lt;span class="n"&gt;get&lt;/span&gt; &lt;span class="s1"&gt;'/results'&lt;/span&gt; &lt;span class="k"&gt;do&lt;/span&gt;
  &lt;span class="vi"&gt;@title&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;'Results so far:'&lt;/span&gt;
  &lt;span class="vi"&gt;@store&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="no"&gt;YAML&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="no"&gt;Store&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;new&lt;/span&gt; &lt;span class="s1"&gt;'votes.yml'&lt;/span&gt;
  &lt;span class="vi"&gt;@votes&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="vi"&gt;@store&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;transaction&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="vi"&gt;@store&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'votes'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="n"&gt;erb&lt;/span&gt; &lt;span class="ss"&gt;:results&lt;/span&gt;
&lt;span class="k"&gt;end&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We are using YAML here to easily manage our voting data.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;YAML stands for YAML Ain't Markup Language. It is a data serialization language that matches user’s expectations about data. It designed to be human friendly and works perfectly with other programming languages. It is highly useful in manage data.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Finally, the web app will look like as:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fbrgtrainings.com%2Fassets%2Fimg%2Ftutorials%2Fvoting-app%2F6.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fbrgtrainings.com%2Fassets%2Fimg%2Ftutorials%2Fvoting-app%2F6.gif" alt="Preview 6"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;There are many areas of improvement here which I leave up to you. This is quite basic and serve as the base for further development.&lt;/p&gt;

&lt;h2&gt;
  
  
  Resources
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="http://sinatrarb.com" rel="noopener noreferrer"&gt;Sinatra Website&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://github.com/sinatra/sinatra/" rel="noopener noreferrer"&gt;Sinatra in GitHub&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://github.com/brgtrainings/voting_app_sinatra" rel="noopener noreferrer"&gt;Source Code&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>html</category>
      <category>css</category>
      <category>ruby</category>
      <category>beginners</category>
    </item>
    <item>
      <title>Coaching experience in 1st Edition of Rails Girls Kathmandu Nepal</title>
      <dc:creator>Budh Ram Gurung</dc:creator>
      <pubDate>Wed, 23 Oct 2019 09:46:11 +0000</pubDate>
      <link>https://dev.to/dhanu/coaching-experience-in-1st-edition-of-rails-girls-kathmandu-nepal-1oe0</link>
      <guid>https://dev.to/dhanu/coaching-experience-in-1st-edition-of-rails-girls-kathmandu-nepal-1oe0</guid>
      <description>&lt;p&gt;&lt;em&gt;As per the Stack OverFlow’s 2019 survey, women comprise nearly 8% in the field of Software Development across the world. In order to improve the participation of women in the IT field, there had been many initiatives started and running all over the world.&lt;br&gt;
One such initiative is the Rails Girls whose aim is to give tools and build a community for women to understand the technology and build their ideas. It was founded at the end of 2010 in Helsinki, Finland.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Note: &lt;a href="https://insights.stackoverflow.com/survey/2019#developer-profile-_-gender"&gt;Stack Overflow’s 2019 Survey&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  How it started
&lt;/h2&gt;

&lt;p&gt;Ever since I came to Nepal in April 2019 I wanted to attend or conduct any Ruby related event. Although I have been introduced into the Ruby Nepal slack long back, frequent interactions started to happened when I joined the &lt;code&gt;railsgirls-nepal&lt;/code&gt; channel in the first week of July after the communication with Ruby Nepal head &lt;a href="https://twitter.com/zoraslapen"&gt;Saroj&lt;/a&gt;. As the name suggests, this channel was created to discuss everything related to organizing &lt;a href="http://railsgirls.com/kathmandu"&gt;Rails Girls Kathmandu&lt;/a&gt;. I went through the previous discussion and gave a few of my suggestions based on the experience of &lt;a href="http://railsgirls.com/pune"&gt;Rails Girls Pune&lt;/a&gt;. Most of the internal communication happened through emails for coaches. I felt good to be chosen as one of the coaches.&lt;/p&gt;

&lt;p&gt;Note: Click here for &lt;a href="http://rubynepal.org/"&gt;Ruby Nepal Community website&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Event Day 1 - Installation
&lt;/h2&gt;

&lt;p&gt;The venue was chosen very far from my dwelling place. It was inside the Banba Group, a company that is solving hard problems on the cutting edge of technology. The host, &lt;a href="https://www.linkedin.com/in/jonathanclarkeireireland/"&gt;Jonathan Clarke&lt;/a&gt; was cool and humble. Interestingly, he is from Ireland, married a Nepalese girl and kind of settled here.&lt;/p&gt;

&lt;p&gt;Day 1 in Rails Girls event is mostly dedicated to getting familiar with your participants and making sure that they are ready for Day 2, the actual workshop. During this day, the organizers or coaches help with the installation of all the pre-requisites required for the workshop. It mostly includes Git, Ruby, and Ruby on Rails.&lt;/p&gt;

&lt;h2&gt;
  
  
  Event Day 2 - Workshop
&lt;/h2&gt;

&lt;p&gt;Although there were nearly eight girls for the installation day, the numbers had increased during the second day to around twelve. It was both good and bad. Good in the sense that each coach now can give more time to help individual participants. However, the number was less than the rest of the world. It shows that the penetration of Ruby is not enough at the moment in Nepal.&lt;/p&gt;

&lt;p&gt;We started with a briefing about the Rails Girls event to all attendees. It includes mostly about how it started, its purpose, how the workshop will be going to happen, etc.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--epdAiKkO--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/1gl06x2htu7fbgqtnb3j.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--epdAiKkO--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/1gl06x2htu7fbgqtnb3j.jpeg" alt="Alt Text" width="880" height="440"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;After that, we all started with the workshop. Our schedule looked like:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Get familiar with Ruby through TryRuby&lt;/li&gt;
&lt;li&gt;Installation of Rails&lt;/li&gt;
&lt;li&gt;Build the first app&lt;/li&gt;
&lt;li&gt;Push the app to GitHub&lt;/li&gt;
&lt;li&gt;Host the app through Heroku&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;I was quite surprised by a few of the participants who really deployed their first application in Heroku. Fewer of them were taking time. We noticed that the participants with Windows OS were taking longer time. They were not able to install a few of the gems(packages) for which we, as a coach, need to intervene and resolve their issues.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Ruby gems are not smoother in Windows in the context of the installation.&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--1IZ_TKz9--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/aldjapw74a127o0x0t0q.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--1IZ_TKz9--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/aldjapw74a127o0x0t0q.png" alt="Alt Text" width="880" height="319"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;After around two o’clock, lunch was served. It was in a package made in an Aluminium and had “MoMo” with french fries and potatoes. We had Pizzas too. It was the local ones. Overall, the lunch was light and delicious. Forgive me for not clicking it pics and sharing it with you.&lt;/p&gt;

&lt;p&gt;Post lunch, we continued with the workshop and focussed on &lt;code&gt;Pushing to GitHub&lt;/code&gt; and &lt;code&gt;Hosting to Heroku&lt;/code&gt; sections. The majority of the participants were able to finish the basic drill of the workshop.&lt;/p&gt;

&lt;p&gt;We all coaches were happy to see with the proceeding.&lt;/p&gt;

&lt;p&gt;The event was officially ended with a group photo.&lt;/p&gt;

&lt;h2&gt;
  
  
  Ending Keynote
&lt;/h2&gt;

&lt;p&gt;My overall experience of coaching was wonderful at this event. I observed that the girls in Nepal have the potential too to meet with the industry expectations. Although the numbers were less for the first edition of Rails Girls Kathmandu as compare to the Pune edition, I have a feeling that it will grow as we organize such events in the future.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Looking forward to the next edition of Rails Girls Kathmandu with our more girls.&lt;/strong&gt;&lt;/p&gt;

</description>
      <category>ruby</category>
      <category>rails</category>
      <category>nepal</category>
      <category>webdev</category>
    </item>
    <item>
      <title>Bloggerfoo - a Jekyll (Ruby) based blogging theme for Developers</title>
      <dc:creator>Budh Ram Gurung</dc:creator>
      <pubDate>Sun, 16 Jun 2019 16:54:14 +0000</pubDate>
      <link>https://dev.to/dhanu/bloggerfoo-a-jekyll-ruby-based-blogging-theme-for-developers-fj8</link>
      <guid>https://dev.to/dhanu/bloggerfoo-a-jekyll-ruby-based-blogging-theme-for-developers-fj8</guid>
      <description>&lt;p&gt;Hi Folks,&lt;/p&gt;

&lt;p&gt;In the process of becoming a theme developer I have started with a developer focussed theme which is simple and mostly shows developer's work.&lt;/p&gt;

&lt;p&gt;There are many such developer theme available but I found that the blog post is not as creative.&lt;/p&gt;

&lt;p&gt;I really like the &lt;a href="https://medium.com"&gt;Medium like Blog post&lt;/a&gt; where it has more creativity as well.&lt;/p&gt;

&lt;p&gt;Would really like to get feedback on it so that I could improve it in better way.&lt;/p&gt;

&lt;p&gt;Site - &lt;a href="https://bloggerfoo.github.io"&gt;https://bloggerfoo.github.io&lt;/a&gt;&lt;br&gt;
Source Code - &lt;a href="https://github.com/bloggerfoo/bloggerfoo.github.io"&gt;https://github.com/bloggerfoo/bloggerfoo.github.io&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Note&lt;/em&gt;&lt;br&gt;
I have migrated my own personal website to it. Feel free to check this as well &lt;a href="https://coolbrg.me"&gt;https://coolbrg.me&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I will be constantly improving it as the time goes.&lt;/p&gt;

</description>
      <category>blogging</category>
      <category>ruby</category>
      <category>jekyll</category>
    </item>
  </channel>
</rss>
