<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:blogger='http://schemas.google.com/blogger/2008' xmlns:georss='http://www.georss.org/georss' xmlns:gd="http://schemas.google.com/g/2005" xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-8243723482882736139</id><updated>2024-03-17T14:45:32.165+05:30</updated><category term="Ruby"/><category term="Rails"/><category term="ruby on rails"/><category term="rails3"/><category term="ajax"/><category term="Rails 3"/><category term="class"/><category term="javascript"/><category term="module"/><category term="nginx"/><category term="private"/><category term="public"/><category term="CRUD"/><category term="CSS"/><category term="Cheat sheet"/><category term="Convert"/><category term="Highcharts"/><category term="Integration"/><category term="JQuery"/><category term="JSON"/><category term="Leaflet"/><category term="Map"/><category term="Minero"/><category term="Roman"/><category term="Sidebar"/><category term="Web"/><category term="accordion"/><category term="active"/><category term="app/views/layouts"/><category term="application"/><category term="application.html.erb"/><category term="assembla"/><category term="base"/><category term="best"/><category term="bitbucket"/><category term="builder"/><category term="cancan"/><category term="ckeditor"/><category term="class_eval"/><category term="clone"/><category term="cloudmade"/><category term="code"/><category term="content_for"/><category term="cruisecontrol"/><category term="current"/><category term="current_path?"/><category term="database"/><category term="david"/><category term="decorator"/><category term="deployment"/><category term="derived"/><category term="design pattern"/><category term="devise"/><category term="dhh"/><category term="director"/><category term="dup"/><category term="dynamically connect"/><category term="escape"/><category term="establish_connection"/><category term="examples"/><category term="expandable"/><category term="explicit"/><category term="free"/><category term="git"/><category term="github"/><category term="h"/><category term="h()"/><category term="helpers"/><category term="heroku"/><category term="highchart"/><category term="highlight"/><category term="highstock"/><category term="host"/><category term="html safe"/><category term="html_escape"/><category term="https"/><category term="implicit"/><category term="inheritance"/><category term="injection"/><category term="instance_eval"/><category term="interactive charts"/><category term="internals"/><category term="javascript charts"/><category term="jquery ui"/><category term="jsfiddle"/><category term="label"/><category term="layouts"/><category term="leaflet on rails"/><category term="legend"/><category term="library"/><category term="marker"/><category term="marker cluster"/><category term="markercluster"/><category term="matz"/><category term="memcached"/><category term="mercurial"/><category term="mercury"/><category term="meta programming"/><category term="method"/><category term="mobile friendly map"/><category term="mongrel"/><category term="multiple Database"/><category term="munin"/><category term="name"/><category term="navigation"/><category term="nesting layouts"/><category term="object"/><category term="one at a time"/><category term="opensource"/><category term="output_safety"/><category term="paperclip"/><category term="passenger"/><category term="passenger_pass_header"/><category term="phusion"/><category term="protected"/><category term="rack"/><category term="rails4"/><category term="raw"/><category term="receiver"/><category term="recursion"/><category term="refinery cms"/><category term="rendering"/><category term="repository"/><category term="ruby discrepancies OOP ruby1.8.7 errors"/><category term="ruby toolbox"/><category term="scope"/><category term="scout"/><category term="section"/><category term="secure"/><category term="singleton"/><category term="source code"/><category term="sphinx"/><category term="ssl"/><category term="ssl_requirement"/><category term="svn"/><category term="tabs"/><category term="taint"/><category term="tainted"/><category term="tap"/><category term="tile"/><category term="tinymce"/><category term="tooltip"/><category term="ui-state-active"/><category term="ui-state-default"/><category term="ui.core.js"/><category term="vcr"/><category term="version control"/><category term="webrick"/><category term="why"/><category term="x-forwarded-proto"/><category term="xAxis"/><category term="x_forwarded_proto"/><category term="yield"/><category term="zoom control"/><category term="zoomfs"/><title type='text'>My Ruby on Rails experiences</title><subtitle type='html'></subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://rorandme.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8243723482882736139/posts/default?redirect=false'/><link rel='alternate' type='text/html' href='http://rorandme.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>20</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-8243723482882736139.post-2463675533353483966</id><published>2014-04-12T12:23:00.000+05:30</published><updated>2014-04-12T12:28:50.742+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="active"/><category scheme="http://www.blogger.com/atom/ns#" term="ajax"/><category scheme="http://www.blogger.com/atom/ns#" term="best"/><category scheme="http://www.blogger.com/atom/ns#" term="class"/><category scheme="http://www.blogger.com/atom/ns#" term="CSS"/><category scheme="http://www.blogger.com/atom/ns#" term="current"/><category scheme="http://www.blogger.com/atom/ns#" term="current_path?"/><category scheme="http://www.blogger.com/atom/ns#" term="helpers"/><category scheme="http://www.blogger.com/atom/ns#" term="highlight"/><category scheme="http://www.blogger.com/atom/ns#" term="navigation"/><category scheme="http://www.blogger.com/atom/ns#" term="Rails"/><category scheme="http://www.blogger.com/atom/ns#" term="Rails 3"/><category scheme="http://www.blogger.com/atom/ns#" term="rails4"/><category scheme="http://www.blogger.com/atom/ns#" term="ruby on rails"/><category scheme="http://www.blogger.com/atom/ns#" term="Sidebar"/><category scheme="http://www.blogger.com/atom/ns#" term="tabs"/><title type='text'>Rails Best Way To Highlight Current Tab</title><content type='html'>&lt;span style=&quot;font-family: &amp;quot;Trebuchet MS&amp;quot;,sans-serif;&quot;&gt;This post is about finding the better way to highlight the current tab on page refresh.&amp;nbsp; &lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;Trebuchet MS&amp;quot;,sans-serif;&quot;&gt;Many times we have the requirement where we have different tabs either in the side bar or top navigation bar and we want to apply a CSS class to highlight the current tab.&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;Trebuchet MS&amp;quot;,sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: &amp;quot;Trebuchet MS&amp;quot;,sans-serif;&quot;&gt;So how to do it&amp;nbsp; ? Here you go - &lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;Trebuchet MS&amp;quot;,sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: &amp;quot;Trebuchet MS&amp;quot;,sans-serif;&quot;&gt;&lt;b&gt;Usual Way:&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;i&gt;&lt;span style=&quot;font-family: &amp;quot;Helvetica Neue&amp;quot;,Arial,Helvetica,sans-serif;&quot;&gt;&lt;b&gt;&amp;nbsp;&lt;/b&gt;&lt;/span&gt;_sidebar.html.erb&lt;/i&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;pre style=&quot;background-image: URL(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh84Rur_tlUxHWvUnwN2JJsDQ-Uyy9JvqOXY_p4_cT7HKqont4q8xVdk4TOUWzDDV4e8LSyc7K6zv3S5MS6QrBwc9VuYtpq2Nk7ui_DcPWYZK5owfyirSU6IZroaF_NLQ7RuvNLwgeZ3BmD/s320/codebg.gif); background: #f0f0f0; border: 1px dashed #CCCCCC; color: black; font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;&quot;&gt;&lt;code style=&quot;color: black; word-wrap: normal;&quot;&gt; &amp;lt;ul id=&quot;sidenav&quot; class=&quot;nav nav-sidebar&quot;&amp;gt;  
   &amp;lt;li id=&quot;dashboard_lnk&quot; class=&quot;&amp;lt;%= controller_name == &#39;dashboard&#39; ? &#39;active&#39; : &#39;&#39; %&amp;gt;&quot;&amp;gt;  
    &amp;lt;%= link_to (content_tag(:span, &#39;&#39;, class: &quot;glyphicon glyphicon-home&quot;) + &#39; &#39; + t(&#39;sidebar.dashboard&#39;, scope: @locale_scope )).html_safe, dashboard_index_path %&amp;gt;  
   &amp;lt;/li&amp;gt;  
   &amp;lt;li id=&quot;business_profile_lnk&quot; class=&quot;&amp;lt;%= controller_name == &#39;business_profiles&#39; ? &#39;active&#39; : &#39;&#39; %&amp;gt;&quot;&amp;gt;  
    &amp;lt;%= link_to (content_tag(:span, &#39;&#39;, class: &quot;glyphicon glyphicon-user&quot;) + &#39; &#39; + t(&#39;sidebar.business_profile&#39;, scope: @locale_scope)).html_safe, building_business_profiles_path(@business_id) %&amp;gt;  
   &amp;lt;/li&amp;gt;  
  &amp;lt;/ul&amp;gt;  
&lt;/code&gt;&lt;/pre&gt;
&lt;br /&gt;
&lt;b&gt;Better Way:&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;i&gt;app/helpers/application_helper.rb&lt;/i&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;pre style=&quot;background-image: URL(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh84Rur_tlUxHWvUnwN2JJsDQ-Uyy9JvqOXY_p4_cT7HKqont4q8xVdk4TOUWzDDV4e8LSyc7K6zv3S5MS6QrBwc9VuYtpq2Nk7ui_DcPWYZK5owfyirSU6IZroaF_NLQ7RuvNLwgeZ3BmD/s320/codebg.gif); background: #f0f0f0; border: 1px dashed #CCCCCC; color: black; font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;&quot;&gt;&lt;code style=&quot;color: black; word-wrap: normal;&quot;&gt; def active_tab_class(*paths)  
    active = false  
    paths.each { |path| active ||= current_page?(path) }  
    active ? &#39;active&#39; : &#39;&#39;  
 end  
&lt;/code&gt;&lt;/pre&gt;
&lt;br /&gt;
_sidebar.html.erb&lt;br /&gt;
&lt;br /&gt;
&lt;pre style=&quot;background-image: URL(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh84Rur_tlUxHWvUnwN2JJsDQ-Uyy9JvqOXY_p4_cT7HKqont4q8xVdk4TOUWzDDV4e8LSyc7K6zv3S5MS6QrBwc9VuYtpq2Nk7ui_DcPWYZK5owfyirSU6IZroaF_NLQ7RuvNLwgeZ3BmD/s320/codebg.gif); background: #f0f0f0; border: 1px dashed #CCCCCC; color: black; font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;&quot;&gt;&lt;code style=&quot;color: black; word-wrap: normal;&quot;&gt; &amp;lt;ul id=&quot;sidenav&quot; class=&quot;nav nav-sidebar&quot;&amp;gt;  
   &amp;lt;li id=&quot;dashboard_lnk&quot; class=&quot;&amp;lt;%= active_tab_class(dashboard_index_path, root_path) %&amp;gt;&quot;&amp;gt;  
    &amp;lt;%= link_to (content_tag(:span, &#39;&#39;, class: &quot;glyphicon glyphicon-home&quot;) + &#39; &#39; + t(&#39;sidebar.dashboard&#39;, scope: @locale_scope )).html_safe, dashboard_index_path %&amp;gt;  
   &amp;lt;/li&amp;gt;  
   &amp;lt;li id=&quot;business_profile_lnk&quot; class=&quot;&amp;lt;%= active_tab_class(building_business_profiles_path(@business_id)) %&amp;gt;&quot;&amp;gt;  
    &amp;lt;%= link_to (content_tag(:span, &#39;&#39;, class: &quot;glyphicon glyphicon-user&quot;) + &#39; &#39; + t(&#39;sidebar.business_profile&#39;, scope: @locale_scope)).html_safe, building_business_profiles_path(@business_id) %&amp;gt;  
   &amp;lt;/li&amp;gt;  
  &amp;lt;/ul&amp;gt;  
&lt;/code&gt;&lt;/pre&gt;
</content><link rel='replies' type='application/atom+xml' href='http://rorandme.blogspot.com/feeds/2463675533353483966/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://rorandme.blogspot.com/2014/04/rails-best-way-to-highlight-current-tab.html#comment-form' title='3 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8243723482882736139/posts/default/2463675533353483966'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8243723482882736139/posts/default/2463675533353483966'/><link rel='alternate' type='text/html' href='http://rorandme.blogspot.com/2014/04/rails-best-way-to-highlight-current-tab.html' title='Rails Best Way To Highlight Current Tab'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>3</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8243723482882736139.post-2419388344070980618</id><published>2013-07-06T19:22:00.000+05:30</published><updated>2013-07-14T18:06:44.193+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="cloudmade"/><category scheme="http://www.blogger.com/atom/ns#" term="Integration"/><category scheme="http://www.blogger.com/atom/ns#" term="javascript"/><category scheme="http://www.blogger.com/atom/ns#" term="Leaflet"/><category scheme="http://www.blogger.com/atom/ns#" term="leaflet on rails"/><category scheme="http://www.blogger.com/atom/ns#" term="library"/><category scheme="http://www.blogger.com/atom/ns#" term="Map"/><category scheme="http://www.blogger.com/atom/ns#" term="marker"/><category scheme="http://www.blogger.com/atom/ns#" term="marker cluster"/><category scheme="http://www.blogger.com/atom/ns#" term="markercluster"/><category scheme="http://www.blogger.com/atom/ns#" term="mobile friendly map"/><category scheme="http://www.blogger.com/atom/ns#" term="Rails 3"/><category scheme="http://www.blogger.com/atom/ns#" term="rails3"/><category scheme="http://www.blogger.com/atom/ns#" term="Ruby"/><category scheme="http://www.blogger.com/atom/ns#" term="ruby on rails"/><category scheme="http://www.blogger.com/atom/ns#" term="tile"/><category scheme="http://www.blogger.com/atom/ns#" term="zoom control"/><category scheme="http://www.blogger.com/atom/ns#" term="zoomfs"/><title type='text'>Rails 3 and Leaflet Maps</title><content type='html'>&lt;br /&gt;
&lt;span style=&quot;color: #666666; font-family: Trebuchet MS, sans-serif;&quot;&gt;Now a days maps speak thousand words. So what is the easy way to integrate map with your web application ?&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #666666; font-family: Trebuchet MS, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;color: #666666; font-family: Trebuchet MS, sans-serif;&quot;&gt;Leaflet library(http://leafletjs.com/) is one of the option. It is an open-source JavaScript library for mobile-friendly interactive maps with just 28kb of JS code.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #666666; font-family: Trebuchet MS, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;color: #666666; font-family: Trebuchet MS, sans-serif;&quot;&gt;Leaflet is &lt;b&gt;not&lt;/b&gt; under MIT licence but it has comparatively&amp;nbsp;&lt;a href=&quot;https://github.com/Leaflet/Leaflet/blob/master/LICENSE&quot; target=&quot;_blank&quot;&gt;liberal licence&lt;/a&gt;.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #666666; font-family: Trebuchet MS, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;color: #666666; font-family: Trebuchet MS, sans-serif;&quot;&gt;This is a sample leaflet map -&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgijQETEMKhkBtA_Y2lRoZzoIyadf9hUOh1i3WDpq2DPlneXPq_Rj5f2Z4rf5WdF9enGVYmzJp648H1Ie0421XudD4hlkSUSUPyKTC9cwxjyhZ218xdVjW8xi5gxgMWN3E-clD018MT2ARM/s1600/Leaflet+-+a+JavaScript+library+for+mobile-friendly+maps.png&quot; imageanchor=&quot;1&quot; style=&quot;clear: left; float: left; margin-bottom: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;243&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgijQETEMKhkBtA_Y2lRoZzoIyadf9hUOh1i3WDpq2DPlneXPq_Rj5f2Z4rf5WdF9enGVYmzJp648H1Ie0421XudD4hlkSUSUPyKTC9cwxjyhZ218xdVjW8xi5gxgMWN3E-clD018MT2ARM/s1600/Leaflet+-+a+JavaScript+library+for+mobile-friendly+maps.png&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
&lt;span style=&quot;color: #666666; font-family: Trebuchet MS, sans-serif;&quot;&gt;Map terminology:&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
&lt;span style=&quot;color: #666666; font-family: Trebuchet MS, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
&lt;span style=&quot;color: #666666; font-family: Trebuchet MS, sans-serif;&quot;&gt;1. Pin shaped icons are called markers&amp;nbsp;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
&lt;span style=&quot;color: #666666; font-family: Trebuchet MS, sans-serif;&quot;&gt;2. Bubble containing a text over the icon is called popup&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
&lt;span style=&quot;color: #666666; font-family: Trebuchet MS, sans-serif;&quot;&gt;3. Map is made up of small small images, they are called tiles.&amp;nbsp;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
&lt;span style=&quot;color: #666666; font-family: Trebuchet MS, sans-serif;&quot;&gt;4. +/- signs in top left corner is called zoom control&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
&lt;span style=&quot;color: #666666; font-family: Trebuchet MS, sans-serif;&quot;&gt;5. &quot;Powered by Leaflet&quot; text in the right bottom corner is called attribution&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
&lt;b&gt;&lt;span style=&quot;font-family: Trebuchet MS, sans-serif;&quot;&gt;How to integrate leaflet library with your rails application ?&lt;/span&gt;&lt;span style=&quot;color: #073763; font-family: Trebuchet MS, sans-serif;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
&lt;span style=&quot;font-family: Trebuchet MS, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
&lt;span style=&quot;color: #666666; font-family: Trebuchet MS, sans-serif;&quot;&gt;Step 1: Download Leaflet and put it into your rails application&amp;nbsp;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
&lt;/div&gt;
&lt;ol&gt;
&lt;li&gt;&lt;span style=&quot;color: #666666; font-family: Trebuchet MS, sans-serif;&quot;&gt;Download latest version of leaflet from&amp;nbsp;&lt;a href=&quot;http://leafletjs.com/download.html&quot;&gt;http://leafletjs.com/download.html&lt;/a&gt;.&amp;nbsp;&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style=&quot;color: #666666; font-family: Trebuchet MS, sans-serif;&quot;&gt;Extract the tar ball.&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style=&quot;color: #666666; font-family: Trebuchet MS, sans-serif;&quot;&gt;Copy the&amp;nbsp;&amp;nbsp;&quot;/Leaflet-Leaflet-0deed73/src/Leaflet.js&quot; file form it and put it under &quot;vendor/assets/javascripts/leaflet/&quot; folder in your rails application&amp;nbsp;&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style=&quot;color: #666666; font-family: Trebuchet MS, sans-serif;&quot;&gt;Update your application.js.erb to require leaflet.js&lt;/span&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;span style=&quot;color: #666666; font-family: Trebuchet MS, sans-serif;&quot;&gt;Step 2: &amp;nbsp;Code your view to show map&lt;/span&gt;&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
&lt;/div&gt;
&lt;ol&gt;
&lt;li&gt;&lt;span style=&quot;color: #666666; font-family: Trebuchet MS, sans-serif;&quot;&gt;Create a div in the page. E.g.&amp;nbsp;&amp;lt;div id=&quot;map&quot;&amp;gt;&amp;lt;/div&amp;gt;&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style=&quot;color: #666666; font-family: Trebuchet MS, sans-serif;&quot;&gt;Add following javascript code in the view page&lt;/span&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;pre style=&quot;background-image: URL(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh84Rur_tlUxHWvUnwN2JJsDQ-Uyy9JvqOXY_p4_cT7HKqont4q8xVdk4TOUWzDDV4e8LSyc7K6zv3S5MS6QrBwc9VuYtpq2Nk7ui_DcPWYZK5owfyirSU6IZroaF_NLQ7RuvNLwgeZ3BmD/s320/codebg.gif); background: #f0f0f0; border: 1px dashed #CCCCCC; color: black; font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;&quot;&gt;&lt;code style=&quot;color: black; word-wrap: normal;&quot;&gt; $(document).ready(function(){  
   var cloudmadeUrl = &#39;http://{s}.tile.cloudmade.com/{key}/22677/256/{z}/{x}/{y}.png&#39;,  
   cloudmadeAttribution = &#39;Map data &amp;amp;copy; 2011 OpenStreetMap contributors, Imagery &amp;amp;copy; 2011 FirstFuel&#39;,  
   cloudmade = new L.TileLayer(cloudmadeUrl, {maxZoom: 18, attribution: cloudmadeAttribution, key: &#39;xxxxxxxxxxxx&#39;  
   }),  
   latlng = new L.LatLng(&amp;lt;%= raw @lat.to_json %&amp;gt;,&amp;lt;%= raw @lng.to_json %&amp;gt;);  
   fsMap = new L.Map(&#39;map&#39;, {center: latlng, zoom:15, zoomControl:false, layers: [cloudmade], scrollWheelZoom : false});     
 });  
&lt;/code&gt;&lt;/pre&gt;
&lt;br /&gt;
&lt;span style=&quot;color: #666666; font-family: Trebuchet MS, sans-serif;&quot;&gt;Step 3: Render the page and you should see the map.&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;span style=&quot;font-family: Trebuchet MS, sans-serif;&quot;&gt;How do map gets rendered&amp;nbsp;?&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Trebuchet MS, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;br /&gt;
&lt;div&gt;
&lt;span style=&quot;color: #666666; font-family: Trebuchet MS, sans-serif;&quot;&gt;Map is rendered in form of map tiles. Map tiles comes from the tile provider. There are many tile providers available in the market. Google is also a map tile provider.&amp;nbsp;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;color: #666666; font-family: Trebuchet MS, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;color: #666666; font-family: Trebuchet MS, sans-serif;&quot;&gt;Default map tile provider for leaflet is cloudmade. You have to mention the map tile provider URL when you create map. See the code snippet in the above section in step 3.&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;color: #666666; font-family: Trebuchet MS, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;pre style=&quot;background-image: URL(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh84Rur_tlUxHWvUnwN2JJsDQ-Uyy9JvqOXY_p4_cT7HKqont4q8xVdk4TOUWzDDV4e8LSyc7K6zv3S5MS6QrBwc9VuYtpq2Nk7ui_DcPWYZK5owfyirSU6IZroaF_NLQ7RuvNLwgeZ3BmD/s320/codebg.gif); background: #f0f0f0; border: 1px dashed #CCCCCC; color: black; font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;&quot;&gt;&lt;code style=&quot;color: black; word-wrap: normal;&quot;&gt; var cloudmadeUrl = &#39;http://{s}.tile.cloudmade.com/API-key/997/256/{z}/{x}/{y}.png&#39;  
&lt;/code&gt;&lt;/pre&gt;
&lt;span style=&quot;color: #666666; font-family: Trebuchet MS, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;color: #666666; font-family: Trebuchet MS, sans-serif;&quot;&gt;Map tiles can also have different styles, the example map picture above shows colorful map. Now if you want to show grey(Black&amp;amp;White) map then you can use the different map style. The number 997 in above URL is an identifier for a map style. Use&amp;nbsp;&lt;b&gt;22677&lt;/b&gt; instead of 997 to see a grey black and white map.&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #666666; font-family: Trebuchet MS, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Trebuchet MS, sans-serif;&quot;&gt;&lt;b&gt;What all cool things you can do with leaflet maps?&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;span style=&quot;color: #666666; font-family: Trebuchet MS, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;color: #666666; font-family: Trebuchet MS, sans-serif;&quot;&gt;1. You can show cluster of markers using a beautiful plugin called &lt;a href=&quot;https://github.com/Leaflet/Leaflet.markercluster&quot;&gt;https://github.com/Leaflet/Leaflet.markercluster&lt;/a&gt;&lt;/span&gt;

&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEif4VvxteCDhHkQrH_6HQPVpS85_FLtB8wev9UVIAX9tppp84XGRxls21EPMNESxj8Dy2GsFMfKz-eNBbbww_xjpbQJpwM53A5v4hgY2nqOuwEgfiqNrOaPbMewW-Dg63Z1sw0BaeOzwApi/s1600/Leaflet+marker+cluster.png&quot; imageanchor=&quot;1&quot; style=&quot;clear: left; float: left; margin-bottom: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;276&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEif4VvxteCDhHkQrH_6HQPVpS85_FLtB8wev9UVIAX9tppp84XGRxls21EPMNESxj8Dy2GsFMfKz-eNBbbww_xjpbQJpwM53A5v4hgY2nqOuwEgfiqNrOaPbMewW-Dg63Z1sw0BaeOzwApi/s1600/Leaflet+marker+cluster.png&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEif4VvxteCDhHkQrH_6HQPVpS85_FLtB8wev9UVIAX9tppp84XGRxls21EPMNESxj8Dy2GsFMfKz-eNBbbww_xjpbQJpwM53A5v4hgY2nqOuwEgfiqNrOaPbMewW-Dg63Z1sw0BaeOzwApi/s1600/Leaflet+marker+cluster.png&quot; imageanchor=&quot;1&quot; style=&quot;clear: left; float: left; margin-bottom: 1em; margin-right: 1em;&quot;&gt;&lt;br /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;span style=&quot;color: #666666; font-family: Trebuchet MS, sans-serif;&quot;&gt;To use this plugin, put&amp;nbsp;&lt;a href=&quot;https://github.com/Leaflet/Leaflet.markercluster/blob/master/src/MarkerCluster.js&quot; style=&quot;text-align: center;&quot;&gt;https://github.com/Leaflet/Leaflet.markercluster/blob/master/src/MarkerCluster.js&lt;/a&gt;&amp;nbsp;to your &amp;lt;RAILS_ROOT&amp;gt;/vendor/assets/javascripts/leaflet and add following code -&amp;nbsp;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;pre style=&quot;background-image: URL(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh84Rur_tlUxHWvUnwN2JJsDQ-Uyy9JvqOXY_p4_cT7HKqont4q8xVdk4TOUWzDDV4e8LSyc7K6zv3S5MS6QrBwc9VuYtpq2Nk7ui_DcPWYZK5owfyirSU6IZroaF_NLQ7RuvNLwgeZ3BmD/s320/codebg.gif); background: #f0f0f0; border: 1px dashed #CCCCCC; color: black; font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;&quot;&gt;&lt;code style=&quot;color: black; word-wrap: normal;&quot;&gt; var markers = new L.MarkerClusterGroup();  
 var m = new L.Marker(new L.LatLng(123,456), {        
       icon : L.icon({  
         iconUrl: http://abc.com/marker-icon.jpg,  
         iconSize: [40, 40]  
       })  
     }).bindLabel(&quot;Hey I am marker&quot;);  
 markers.addLayer(m);  
 map.addLayer(markers);  
&lt;/code&gt;&lt;/pre&gt;
&lt;br /&gt;
&lt;span style=&quot;color: #666666; font-family: Trebuchet MS, sans-serif;&quot;&gt;What is you want to change the icon for the cluster, say you don&#39;t like the circle. Then use the followong code and use CSS to do the magic for you.&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;pre style=&quot;background-image: URL(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh84Rur_tlUxHWvUnwN2JJsDQ-Uyy9JvqOXY_p4_cT7HKqont4q8xVdk4TOUWzDDV4e8LSyc7K6zv3S5MS6QrBwc9VuYtpq2Nk7ui_DcPWYZK5owfyirSU6IZroaF_NLQ7RuvNLwgeZ3BmD/s320/codebg.gif); background: #f0f0f0; border: 1px dashed #CCCCCC; color: black; font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;&quot;&gt;&lt;code style=&quot;color: black; word-wrap: normal;&quot;&gt; var markers = new L.MarkerClusterGroup({  
   iconCreateFunction: function(cluster) {  
     return new L.DivIcon({ html: &#39;&amp;lt;b&amp;gt;&#39; + cluster.getChildCount() + &#39;&amp;lt;/b&amp;gt;&#39; });  
   }  
 });  
&lt;/code&gt;&lt;/pre&gt;
&lt;br /&gt;
&lt;span style=&quot;color: #666666; font-family: Trebuchet MS, sans-serif;&quot;&gt;Now what if you want to see your map in full screen the use this plugin&amp;nbsp;https://github.com/elidupuis/leaflet.zoomfs and add&amp;nbsp;&lt;a href=&quot;https://github.com/elidupuis/leaflet.zoomfs/blob/master/leaflet.zoomfs.js&quot;&gt;https://github.com/elidupuis/leaflet.zoomfs/blob/master/leaflet.zoomfs.js&lt;/a&gt;&amp;nbsp;to your &amp;lt;RAILS_ROOT&amp;gt;/vendor/assets/javascripts/leaflet folder and add following code -&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;pre style=&quot;background-image: URL(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh84Rur_tlUxHWvUnwN2JJsDQ-Uyy9JvqOXY_p4_cT7HKqont4q8xVdk4TOUWzDDV4e8LSyc7K6zv3S5MS6QrBwc9VuYtpq2Nk7ui_DcPWYZK5owfyirSU6IZroaF_NLQ7RuvNLwgeZ3BmD/s320/codebg.gif); background: #f0f0f0; border: 1px dashed #CCCCCC; color: black; font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;&quot;&gt;&lt;code style=&quot;color: black; word-wrap: normal;&quot;&gt; map = new L.Map(&#39;map&#39;, {center: latlng, zoom:15, zoomControl:false, layers: [cloudmade], scrollWheelZoom : false});  
 var zoomFS = new L.Control.ZoomFS({position : &#39;bottomleft&#39;});  
 map.addControl(zoomFS);  
 map.on(&#39;enterFullscreen&#39;, function() {  
    $(&#39;#my-box&#39;).css({  
     &#39;position&#39; : &quot;fixed&quot;,  
     &quot;top&quot; : &quot;40px&quot;,  
     &quot;left&quot; : &quot;0px&quot;  
    })     
 });  
 map.on(&#39;exitFullscreen&#39;, function() {  
    $(&#39;#my-box&#39;).css({  
     &#39;position&#39; : &quot;absolute&quot;,  
     &quot;top&quot; : &quot;0px&quot;  
    })  
 });  
&lt;/code&gt;&lt;/pre&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: Trebuchet MS, sans-serif;&quot;&gt;&lt;b&gt;Started loving it? &lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;</content><link rel='replies' type='application/atom+xml' href='http://rorandme.blogspot.com/feeds/2419388344070980618/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://rorandme.blogspot.com/2013/07/rails-3-integration-with-map-using.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8243723482882736139/posts/default/2419388344070980618'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8243723482882736139/posts/default/2419388344070980618'/><link rel='alternate' type='text/html' href='http://rorandme.blogspot.com/2013/07/rails-3-integration-with-map-using.html' title='Rails 3 and Leaflet Maps'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgijQETEMKhkBtA_Y2lRoZzoIyadf9hUOh1i3WDpq2DPlneXPq_Rj5f2Z4rf5WdF9enGVYmzJp648H1Ie0421XudD4hlkSUSUPyKTC9cwxjyhZ218xdVjW8xi5gxgMWN3E-clD018MT2ARM/s72-c/Leaflet+-+a+JavaScript+library+for+mobile-friendly+maps.png" height="72" width="72"/><thr:total>0</thr:total><georss:featurename>Pune, Maharashtra, India</georss:featurename><georss:point>18.5204303 73.856743699999925</georss:point><georss:box>18.2795348 73.534020199999929 18.7613258 74.17946719999992</georss:box></entry><entry><id>tag:blogger.com,1999:blog-8243723482882736139.post-2027339163793542654</id><published>2012-08-24T01:44:00.000+05:30</published><updated>2012-08-24T01:45:00.502+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="database"/><category scheme="http://www.blogger.com/atom/ns#" term="dynamically connect"/><category scheme="http://www.blogger.com/atom/ns#" term="establish_connection"/><category scheme="http://www.blogger.com/atom/ns#" term="multiple Database"/><category scheme="http://www.blogger.com/atom/ns#" term="rails3"/><category scheme="http://www.blogger.com/atom/ns#" term="Ruby"/><category scheme="http://www.blogger.com/atom/ns#" term="ruby on rails"/><title type='text'>Rails 3 Dynamically Connect With Multiple Databases  </title><content type='html'>If you are dealing with a sort of distributed application where you have some data sharing happening through databases then you may need to connect to more then one database at run time. It can be achieved in following simplest way.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Step 1: Add the connection method in Application controller&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
You can have any number connector methods which can get you connected to desired DB&lt;br /&gt;
&lt;br /&gt;
&lt;pre style=&quot;background-image: URL(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh84Rur_tlUxHWvUnwN2JJsDQ-Uyy9JvqOXY_p4_cT7HKqont4q8xVdk4TOUWzDDV4e8LSyc7K6zv3S5MS6QrBwc9VuYtpq2Nk7ui_DcPWYZK5owfyirSU6IZroaF_NLQ7RuvNLwgeZ3BmD/s320/codebg.gif); background: #f0f0f0; border: 1px dashed #CCCCCC; color: black; font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;&quot;&gt;&lt;code style=&quot;color: black; word-wrap: normal;&quot;&gt; def connect_to_db_first  
   params = DBBroker::FirstDatabase.get_db_connection_params()  
   DBBroker::FirstDatabase.set_db_connection(params)  
 end  
&lt;/code&gt;&lt;/pre&gt;
&lt;br /&gt;
&lt;b&gt;Step 2: Add a Ruby Module under lib (Responsible for getting DB connection params and do actual connection)&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;br /&gt;&lt;/b&gt;
&lt;br /&gt;
This module will have all the classes which can get you connected to different DB. A Database connector class will have one method to get the DB connection parameters (you can call web service for the same, line 14 below) and second method to do the actual connection&lt;br /&gt;
&lt;br /&gt;
&lt;pre style=&quot;background-image: URL(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh84Rur_tlUxHWvUnwN2JJsDQ-Uyy9JvqOXY_p4_cT7HKqont4q8xVdk4TOUWzDDV4e8LSyc7K6zv3S5MS6QrBwc9VuYtpq2Nk7ui_DcPWYZK5owfyirSU6IZroaF_NLQ7RuvNLwgeZ3BmD/s320/codebg.gif); background: #f0f0f0; border: 1px dashed #CCCCCC; color: black; font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;&quot;&gt;&lt;code style=&quot;color: black; word-wrap: normal;&quot;&gt;1:  module DBBroker   
2:    class FirstDatabase &amp;lt; ActiveRecord::Base   
3:     def self.set_db_connection(params)   
4:      establish_connection( :adapter =&amp;gt; params[:adapter],   
5:          :host  =&amp;gt; params[:host] ,   
6:          :username =&amp;gt; params[:username] ,   
7:          :password =&amp;gt; params[:password],   
8:          :database =&amp;gt; params[:database],   
9:          :port =&amp;gt; params[:port].to_i,   
10:          :encoding =&amp;gt; &#39;utf8&#39;   
11:         )   
12:     end   
13:     def self.get_db_connection_params(connect_to)   
14:      db_params = DBProperties.fetch(connect_to)   
15:      params = Hash.new   
16:      params[:adapter] = &quot;mysql2&quot;   
17:      params[:host] = db_params.server_name.to_s   
18:      params[:username] = db_params.user_name.to_s   
19:      params[:password] = db_params.password.to_s   
20:      params[:database] = db_params.schema_name.to_s   
21:      params[:port] = db_params.port.to_s   
22:      return params   
23:     end    
24:    end   
25:  end   
&lt;/code&gt;&lt;/pre&gt;
&lt;br /&gt;
&lt;b&gt;Step 3: Add the Dynamic connection code as before filter in your controllers (wherever required)&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;br /&gt;&lt;/b&gt;
&lt;br /&gt;
A filter will get you connected to desired DB before the processing happens&lt;br /&gt;
&lt;b&gt;&lt;br /&gt;&lt;/b&gt;
&lt;br /&gt;
&lt;pre style=&quot;background-image: URL(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh84Rur_tlUxHWvUnwN2JJsDQ-Uyy9JvqOXY_p4_cT7HKqont4q8xVdk4TOUWzDDV4e8LSyc7K6zv3S5MS6QrBwc9VuYtpq2Nk7ui_DcPWYZK5owfyirSU6IZroaF_NLQ7RuvNLwgeZ3BmD/s320/codebg.gif); background: #f0f0f0; border: 1px dashed #CCCCCC; color: black; font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;&quot;&gt;&lt;code style=&quot;color: black; word-wrap: normal;&quot;&gt; class ProductsController &amp;lt; ApplicationController  
  before_filter :login_required, :connect_to_db_first  
  def new  
   @product = Product.new   
  end  
 end  
&lt;/code&gt;&lt;/pre&gt;
&lt;b&gt;&lt;br /&gt;&lt;/b&gt;
&lt;b&gt;Step 4: Change your models to connect to particular DB


&lt;/b&gt;
&lt;br /&gt;
&lt;b&gt;&lt;br /&gt;&lt;/b&gt;
Model based on within which database they exist ... they inherit corresponding DB connector class&lt;br /&gt;
&lt;b&gt;&lt;br /&gt;&lt;/b&gt;
&lt;br /&gt;
&lt;pre style=&quot;background-image: URL(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh84Rur_tlUxHWvUnwN2JJsDQ-Uyy9JvqOXY_p4_cT7HKqont4q8xVdk4TOUWzDDV4e8LSyc7K6zv3S5MS6QrBwc9VuYtpq2Nk7ui_DcPWYZK5owfyirSU6IZroaF_NLQ7RuvNLwgeZ3BmD/s320/codebg.gif); background: #f0f0f0; border: 1px dashed #CCCCCC; color: black; font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;&quot;&gt;&lt;code style=&quot;color: black; word-wrap: normal;&quot;&gt; class Product &amp;lt; DatabaseConnecter::FirstDatabase  
  set_table_name :products  
 end  
&lt;/code&gt;&lt;/pre&gt;
</content><link rel='replies' type='application/atom+xml' href='http://rorandme.blogspot.com/feeds/2027339163793542654/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://rorandme.blogspot.com/2012/08/rails-3-dynamically-connect-with.html#comment-form' title='3 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8243723482882736139/posts/default/2027339163793542654'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8243723482882736139/posts/default/2027339163793542654'/><link rel='alternate' type='text/html' href='http://rorandme.blogspot.com/2012/08/rails-3-dynamically-connect-with.html' title='Rails 3 Dynamically Connect With Multiple Databases  '/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>3</thr:total><georss:featurename>Pune, Maharashtra, India</georss:featurename><georss:point>18.5204303 73.8567437</georss:point><georss:box>18.3999798 73.6988152 18.6408808 74.014672199999993</georss:box></entry><entry><id>tag:blogger.com,1999:blog-8243723482882736139.post-6295286508368236184</id><published>2012-08-22T23:50:00.000+05:30</published><updated>2012-08-25T01:19:20.947+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="ajax"/><category scheme="http://www.blogger.com/atom/ns#" term="highchart"/><category scheme="http://www.blogger.com/atom/ns#" term="Highcharts"/><category scheme="http://www.blogger.com/atom/ns#" term="highstock"/><category scheme="http://www.blogger.com/atom/ns#" term="interactive charts"/><category scheme="http://www.blogger.com/atom/ns#" term="javascript"/><category scheme="http://www.blogger.com/atom/ns#" term="javascript charts"/><category scheme="http://www.blogger.com/atom/ns#" term="jsfiddle"/><category scheme="http://www.blogger.com/atom/ns#" term="JSON"/><category scheme="http://www.blogger.com/atom/ns#" term="label"/><category scheme="http://www.blogger.com/atom/ns#" term="legend"/><category scheme="http://www.blogger.com/atom/ns#" term="Rails"/><category scheme="http://www.blogger.com/atom/ns#" term="rails3"/><category scheme="http://www.blogger.com/atom/ns#" term="Ruby"/><category scheme="http://www.blogger.com/atom/ns#" term="ruby on rails"/><category scheme="http://www.blogger.com/atom/ns#" term="tooltip"/><category scheme="http://www.blogger.com/atom/ns#" term="xAxis"/><title type='text'>Rails 3 and HighCharts</title><content type='html'>&lt;b&gt;Overview&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;br /&gt;&lt;/b&gt;
Highcharts are interactive Javascript charts which you can use very easily with any Rails application. I used them for one of my rails project related to Analytics.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Basics&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;br /&gt;&lt;/b&gt;
But the only difficulty which I faced is the knowledge of Highchart basics. See what are the different HighChart elements called in following image -&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjr5hU5Teser_w9JzHJ9rVk047BVEZ6xd3NZnkXDOykG8v2xEdCRQN5BRTKIzoyfrcboFfMcYoXUVDD4KOExZ5p3LvvVr-1KGG9KGPLwsrgBCp2y_8VnmOZMj2SjX7yA_d6u_ZO_-lG-4Qx/s1600/highcharts.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;411&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjr5hU5Teser_w9JzHJ9rVk047BVEZ6xd3NZnkXDOykG8v2xEdCRQN5BRTKIzoyfrcboFfMcYoXUVDD4KOExZ5p3LvvVr-1KGG9KGPLwsrgBCp2y_8VnmOZMj2SjX7yA_d6u_ZO_-lG-4Qx/s640/highcharts.png&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;b&gt;Get Started&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;br /&gt;&lt;/b&gt;
Now I will share different code snippets so you can get started with &amp;nbsp;highcharts.&lt;br /&gt;
&lt;br /&gt;
There are 2 types of highchart APIs -&lt;br /&gt;
&lt;br /&gt;
1. &lt;a href=&quot;http://api.highcharts.com/highcharts&quot; target=&quot;_blank&quot;&gt;Highchart API&lt;/a&gt; - Similar to image above but it doesn&#39;t have navigator&lt;br /&gt;
2. &lt;a href=&quot;http://api.highcharts.com/highstock&quot; target=&quot;_blank&quot;&gt;HighStock API&lt;/a&gt; - Image as shown above&lt;br /&gt;
&lt;br /&gt;
&lt;u&gt;A simple Highstock code (HTML):&lt;/u&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Line 1: A div where Highstock chart will be rendered.&lt;br /&gt;
Line 2, 3: Javascripts required for rendering the Highchart&lt;br /&gt;
Line 4: Javascript which provides data to render series on the chart&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;pre style=&quot;background-image: URL(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh84Rur_tlUxHWvUnwN2JJsDQ-Uyy9JvqOXY_p4_cT7HKqont4q8xVdk4TOUWzDDV4e8LSyc7K6zv3S5MS6QrBwc9VuYtpq2Nk7ui_DcPWYZK5owfyirSU6IZroaF_NLQ7RuvNLwgeZ3BmD/s320/codebg.gif); background: #f0f0f0; border: 1px dashed #CCCCCC; color: black; font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;&quot;&gt;&lt;code style=&quot;color: black; word-wrap: normal;&quot;&gt;1:  &amp;lt;div id=&quot;container&quot; style=&quot;height: 400px; min-width: 600px&quot;&amp;gt;&amp;lt;/div&amp;gt;  
2:  &amp;lt;script src=&quot;http://code.highcharts.com/stock/highstock.js&quot;&amp;gt;&amp;lt;/script&amp;gt;  
3:  &amp;lt;script src=&quot;http://code.highcharts.com/stock/modules/exporting.js&quot;&amp;gt;&amp;lt;/script&amp;gt;  
4:  &amp;lt;script type=&quot;text/javascript&quot; src=&quot;http://www.highcharts.com/samples/data/three-series-1000-points.js&quot;&amp;gt;&amp;lt;/script&amp;gt;​  
&lt;/code&gt;&lt;/pre&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;u&gt;JavaScript - Responsible for rendering the chart&lt;/u&gt;&lt;br /&gt;
&lt;br /&gt;
Line 2: Highstock initialization&lt;br /&gt;
Line 4: Specify the div where you want to place the highchart&lt;br /&gt;
Line 6-16: To show the legend as shown in the image above&lt;br /&gt;
Line 17-19: To show range selector as shown in the image above&lt;br /&gt;
Line 20-26: Data series for the chart. (You can have more then one series on the chart)&lt;br /&gt;
&lt;u&gt;&lt;br /&gt;&lt;/u&gt;
&lt;br /&gt;
&lt;pre style=&quot;background-image: URL(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh84Rur_tlUxHWvUnwN2JJsDQ-Uyy9JvqOXY_p4_cT7HKqont4q8xVdk4TOUWzDDV4e8LSyc7K6zv3S5MS6QrBwc9VuYtpq2Nk7ui_DcPWYZK5owfyirSU6IZroaF_NLQ7RuvNLwgeZ3BmD/s320/codebg.gif); background: #f0f0f0; border: 1px dashed #CCCCCC; color: black; font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;&quot;&gt;&lt;code style=&quot;color: black; word-wrap: normal;&quot;&gt;1:  $(function() {  
2:    var chart = new Highcharts.StockChart({  
3:      chart: {  
4:        renderTo: &#39;container&#39;  
5:      },  
6:      legend: {  
7:        enabled: true,  
8:        align: &#39;right&#39;,  
9:        backgroundColor: &#39;#FCFFC5&#39;,  
10:        borderColor: &#39;black&#39;,  
11:        borderWidth: 2,  
12:        layout: &#39;vertical&#39;,  
13:        verticalAlign: &#39;top&#39;,  
14:        y: 100,  
15:        shadow: true  
16:      },  
17:      rangeSelector: {  
18:        selected: 1  
19:      },  
20:      series: [{  
21:        name: &#39;ADBE&#39;,  
22:        data: ADBE  
23:      }, {  
24:        name: &#39;MSFT&#39;,  
25:        data: MSFT  
26:      }]  
27:    });  
28:  });​  
&lt;/code&gt;&lt;/pre&gt;
&lt;u&gt;&lt;br /&gt;&lt;/u&gt;
&lt;u&gt;See it in action&lt;/u&gt;&lt;br /&gt;
&lt;br /&gt;
Refer to &lt;a href=&quot;http://jsfiddle.net/gh/get/jquery/1.7.2/highslide-software/highcharts.com/tree/master/samples/stock/legend/align/&quot; target=&quot;_blank&quot;&gt;this&lt;/a&gt; JS Fiddle to play with the chart mentioned above.&amp;nbsp;JsFiddle is a playground for web developers, a tool which may be used in many ways. One can use it as an online editor for snippets build from HTML, CSS and JavaScript.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Experimenting with HighCharts&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;br /&gt;&lt;/b&gt;
&lt;u&gt;1. Fetching the chart series JSON data from the remote URL&amp;nbsp;&lt;/u&gt;&lt;br /&gt;
&lt;u&gt;&lt;br /&gt;&lt;/u&gt;
&lt;br /&gt;
&lt;pre style=&quot;background-image: URL(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh84Rur_tlUxHWvUnwN2JJsDQ-Uyy9JvqOXY_p4_cT7HKqont4q8xVdk4TOUWzDDV4e8LSyc7K6zv3S5MS6QrBwc9VuYtpq2Nk7ui_DcPWYZK5owfyirSU6IZroaF_NLQ7RuvNLwgeZ3BmD/s320/codebg.gif); background: #f0f0f0; border: 1px dashed #CCCCCC; color: black; font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;&quot;&gt;&lt;code style=&quot;color: black; word-wrap: normal;&quot;&gt; $.getJSON(&quot;/analytics/chart/monthly_data?site_id=12345&quot;, function(data) {  
   var chart = new Highcharts.StockChart({  
     chart: {  
       renderTo: &#39;container&#39;  
     },          
     series: [{  
       type: &#39;line&#39;,   
       name: &#39;MSFT&#39;,  
       data: data  
     }]  
   });  
 });     
&lt;/code&gt;&lt;/pre&gt;
&lt;br /&gt;
&lt;u&gt;2. Modify the default chart tooltip&lt;/u&gt;

&lt;br /&gt;
&lt;u&gt;&lt;br /&gt;&lt;/u&gt;
Line 2: Only if it is true, then you will get tooltip from all the series&lt;br /&gt;
Line 7: this.x gives you the value on the selected xAxis point&lt;br /&gt;
&lt;br /&gt;
&lt;pre style=&quot;background-image: URL(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh84Rur_tlUxHWvUnwN2JJsDQ-Uyy9JvqOXY_p4_cT7HKqont4q8xVdk4TOUWzDDV4e8LSyc7K6zv3S5MS6QrBwc9VuYtpq2Nk7ui_DcPWYZK5owfyirSU6IZroaF_NLQ7RuvNLwgeZ3BmD/s320/codebg.gif); background: #f0f0f0; border: 1px dashed #CCCCCC; color: black; font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;&quot;&gt;&lt;code style=&quot;color: black; word-wrap: normal;&quot;&gt;1:  tooltip: {  
2:       shared: true,  
3:       formatter: function(){  
4:        var p = &#39;&#39;;  
5:        var actual = &#39;&#39;;  
6:        var predicted = 0;  
7:        p += &#39;&amp;lt;b&amp;gt;&#39;+ this.x +&#39;&amp;lt;/b&amp;gt;&amp;lt;br/&amp;gt;&#39;;  
8:        $.each(this.points, function(i, series){  
9:         if(this.series.name == Decrease&#39; &amp;amp;&amp;amp; this.y &amp;gt; 0){  
10:          p += &#39;&amp;lt;span style=&quot;font-weight:bold;color:&#39;+ this.series.color +&#39;&quot;&amp;gt;&#39; + this.series.name + &#39;:&amp;lt;/span&amp;gt;&#39;;  
11:         }  
12:         if(this.series.name == Increase&#39; &amp;amp;&amp;amp; this.y &amp;lt; 0){  
13:          p += &#39;&amp;lt;span style=&quot;font-weight:bold;color:&#39;+ this.series.color +&#39;&quot;&amp;gt;&#39; + this.series.name + &#39;:&amp;lt;/span&amp;gt;&#39;;  
14:         }  
15:         if(this.series.name == &#39;Actual&#39;){  
16:          p += &#39;&amp;lt;span style=&quot;font-weight:bold;color:&#39;+ this.series.color +&#39;&quot;&amp;gt;&#39; + this.series.name + &#39;:&amp;lt;/span&amp;gt;&#39;;  
17:          p += &#39;&amp;lt;b&amp;gt;&#39; + Highcharts.numberFormat(actual, 0) + &#39; kWh&amp;lt;/b&amp;gt;&amp;lt;br/&amp;gt;&#39;;  
18:         }  
19:         if(this.series.name == &#39;Predicted&#39;){  
20:          p += &#39;&amp;lt;span style=&quot;font-weight:bold;color:&#39;+ this.series.color +&#39;&quot;&amp;gt;&#39; + this.series.name + &#39;:&amp;lt;/span&amp;gt;&#39;;         p += &#39;&amp;lt;b&amp;gt;&#39; + Highcharts.numberFormat(predicted, 0) + &#39; kWh&amp;lt;/b&amp;gt;&amp;lt;br/&amp;gt;&#39;;  
21:         }  
22:        });        
23:        return p;  
24:       }  
25:      }  
&lt;/code&gt;&lt;/pre&gt;
&lt;b&gt;&lt;br /&gt;&lt;/b&gt;
&lt;u&gt;3. Load the chart with animation&amp;nbsp;&lt;/u&gt;&lt;br /&gt;
&lt;u&gt;&lt;br /&gt;&lt;/u&gt;
&lt;br /&gt;
&lt;pre style=&quot;background-image: URL(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh84Rur_tlUxHWvUnwN2JJsDQ-Uyy9JvqOXY_p4_cT7HKqont4q8xVdk4TOUWzDDV4e8LSyc7K6zv3S5MS6QrBwc9VuYtpq2Nk7ui_DcPWYZK5owfyirSU6IZroaF_NLQ7RuvNLwgeZ3BmD/s320/codebg.gif); background: #f0f0f0; border: 1px dashed #CCCCCC; color: black; font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;&quot;&gt;&lt;code style=&quot;color: black; word-wrap: normal;&quot;&gt; $(function() {  
   var chart = new Highcharts.Chart({  
     chart: {  
       renderTo: &#39;container&#39;,  
       defaultSeriesType: &#39;area&#39;  
     },  
     legend: {  
       enabled: true,  
       align: &#39;right&#39;,  
       backgroundColor: &#39;#FCFFC5&#39;,  
       borderColor: &#39;black&#39;,  
       borderWidth: 2,  
       layout: &#39;vertical&#39;,  
       verticalAlign: &#39;top&#39;,  
       y: 100,  
       shadow: true  
     },  
     rangeSelector: {  
       selected: 1  
     },  
     series: []  
   });  
   $(&quot;#container&quot;).queue(&quot;chartQueue&quot;,  
     function(next) {  
       chart.showLoading(&quot;ADBE&quot;);  
       chart.addSeries(  
       {  
         name: &#39;ADBE&#39;,  
         marker: {  
           enabled: false  
         },  
         data: ADBE  
       });  
       setTimeout(function() {  
         chart.hideLoading();  
       }, 3000);  
       next();  
     });  
   $(&quot;#container&quot;).delay(3000, &quot;chartQueue&quot;);  
   $(&quot;#container&quot;).queue(&quot;chartQueue&quot;,  
     function(next) {  
       chart.showLoading(&quot;MSFT&quot;);  
       chart.addSeries(  
       {  
         name: &#39;MSFT&#39;,  
         marker: {  
           enabled: false  
         },  
         data: MSFT  
       });  
       setTimeout(function() {  
         chart.hideLoading();  
       }, 3000);  
       next();  
     });  
   $(&quot;#container&quot;).delay(3000, &quot;chartQueue&quot;);  
   $(&quot;#container&quot;).dequeue(&quot;chartQueue&quot;);  
 });​  
&lt;/code&gt;&lt;/pre&gt;
&lt;b&gt;&lt;br /&gt;&lt;/b&gt;
&lt;b&gt;References&lt;/b&gt;&lt;br /&gt;
&lt;ol&gt;
&lt;li&gt;&lt;b&gt;&lt;a href=&quot;http://www.highcharts.com/&quot;&gt;http://www.highcharts.com/&lt;/a&gt;
&lt;/b&gt;&lt;/li&gt;
&lt;/ol&gt;
</content><link rel='replies' type='application/atom+xml' href='http://rorandme.blogspot.com/feeds/6295286508368236184/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://rorandme.blogspot.com/2012/08/rails-3-and-highcharts.html#comment-form' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8243723482882736139/posts/default/6295286508368236184'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8243723482882736139/posts/default/6295286508368236184'/><link rel='alternate' type='text/html' href='http://rorandme.blogspot.com/2012/08/rails-3-and-highcharts.html' title='Rails 3 and HighCharts'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjr5hU5Teser_w9JzHJ9rVk047BVEZ6xd3NZnkXDOykG8v2xEdCRQN5BRTKIzoyfrcboFfMcYoXUVDD4KOExZ5p3LvvVr-1KGG9KGPLwsrgBCp2y_8VnmOZMj2SjX7yA_d6u_ZO_-lG-4Qx/s72-c/highcharts.png" height="72" width="72"/><thr:total>1</thr:total><georss:featurename>Pune, Maharashtra, India</georss:featurename><georss:point>18.5204303 73.8567437</georss:point><georss:box>18.3998323 73.6988152 18.641028300000002 74.014672199999993</georss:box></entry><entry><id>tag:blogger.com,1999:blog-8243723482882736139.post-3819634623893663474</id><published>2012-06-24T12:06:00.000+05:30</published><updated>2012-08-22T23:59:43.686+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="cancan"/><category scheme="http://www.blogger.com/atom/ns#" term="ckeditor"/><category scheme="http://www.blogger.com/atom/ns#" term="cruisecontrol"/><category scheme="http://www.blogger.com/atom/ns#" term="devise"/><category scheme="http://www.blogger.com/atom/ns#" term="heroku"/><category scheme="http://www.blogger.com/atom/ns#" term="memcached"/><category scheme="http://www.blogger.com/atom/ns#" term="mercury"/><category scheme="http://www.blogger.com/atom/ns#" term="mongrel"/><category scheme="http://www.blogger.com/atom/ns#" term="munin"/><category scheme="http://www.blogger.com/atom/ns#" term="nginx"/><category scheme="http://www.blogger.com/atom/ns#" term="paperclip"/><category scheme="http://www.blogger.com/atom/ns#" term="refinery cms"/><category scheme="http://www.blogger.com/atom/ns#" term="Ruby"/><category scheme="http://www.blogger.com/atom/ns#" term="ruby on rails"/><category scheme="http://www.blogger.com/atom/ns#" term="ruby toolbox"/><category scheme="http://www.blogger.com/atom/ns#" term="scout"/><category scheme="http://www.blogger.com/atom/ns#" term="sphinx"/><category scheme="http://www.blogger.com/atom/ns#" term="tinymce"/><category scheme="http://www.blogger.com/atom/ns#" term="vcr"/><category scheme="http://www.blogger.com/atom/ns#" term="webrick"/><title type='text'>Standard Toolbox for Ruby on Rails projects</title><content type='html'>&lt;h3&gt;



&lt;b style=&quot;background-color: white;&quot;&gt;IDEs:&lt;/b&gt;&lt;/h3&gt;
&lt;ol&gt;
&lt;li&gt;&lt;span style=&quot;background-color: white;&quot;&gt;Nice but Paid for all operating systems - Rubymine (&lt;/span&gt;&lt;a href=&quot;http://www.jetbrains.com/ruby/&quot; style=&quot;background-color: white;&quot;&gt;http://www.jetbrains.com/ruby/&lt;/a&gt;&lt;span style=&quot;background-color: white;&quot;&gt;)&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style=&quot;background-color: white;&quot;&gt;For Mac users -&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;background-color: white;&quot;&gt;TextMate (
&lt;/span&gt;&lt;a href=&quot;http://macromates.com/&quot; style=&quot;background-color: white;&quot;&gt;http://macromates.com/&lt;/a&gt;&lt;span style=&quot;background-color: white;&quot;&gt;)&amp;nbsp;&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style=&quot;background-color: white;&quot;&gt;Good for all operating systems - NetBeans 6.9 ml Ruby (&lt;/span&gt;&lt;a href=&quot;http://netbeans.org/features/ruby/index.html&quot; style=&quot;background-color: white;&quot;&gt;http://netbeans.org/features/ruby/index.html&lt;/a&gt;&lt;span style=&quot;background-color: white;&quot;&gt;)&lt;/span&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;b style=&quot;background-color: white;&quot;&gt;Authentication:&lt;/b&gt;&lt;br /&gt;
&lt;ol&gt;
&lt;li&gt;&lt;span style=&quot;background-color: white;&quot;&gt;Devise (&lt;a href=&quot;http://github.com/plataformatec/devise&quot;&gt;http://github.com/plataformatec/devise&lt;/a&gt;)&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style=&quot;background-color: white;&quot;&gt;authlogic (&lt;a href=&quot;http://github.com/binarylogic/authlogic&quot;&gt;http://github.com/binarylogic/authlogic&lt;/a&gt;)&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style=&quot;background-color: white;&quot;&gt;Restful Authentication (&lt;a href=&quot;http://github.com/technoweenie/restful-authentication&quot;&gt;http://github.com/technoweenie/restful-authentication&lt;/a&gt;)&lt;/span&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;b style=&quot;background-color: white;&quot;&gt;Authorization:&lt;/b&gt;&lt;br /&gt;
&lt;ol&gt;
&lt;li&gt;&lt;span style=&quot;background-color: white;&quot;&gt;CanCan (&lt;a href=&quot;http://github.com/ryanb/cancan&quot;&gt;http://github.com/ryanb/cancan&lt;/a&gt;)&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style=&quot;background-color: white;&quot;&gt;Declarative Authorization (&lt;a href=&quot;http://github.com/stffn/declarative_authorization&quot;&gt;http://github.com/stffn/declarative_authorization&lt;/a&gt;)&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style=&quot;background-color: white; font-family: Arial, &#39;Liberation Sans&#39;, &#39;DejaVu Sans&#39;, sans-serif; font-size: 14px; line-height: 18px; text-align: left;&quot;&gt;Authlogic (&lt;a href=&quot;http://github.com/binarylogic/authlogic&quot;&gt;http://github.com/binarylogic/authlogic&lt;/a&gt;)&lt;/span&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;b style=&quot;background-color: white;&quot;&gt;Search:&lt;/b&gt;&lt;br /&gt;
&lt;ol&gt;
&lt;li&gt;&lt;span style=&quot;background-color: white; font-family: Arial, &#39;Liberation Sans&#39;, &#39;DejaVu Sans&#39;, sans-serif; font-size: 14px; line-height: 18px; text-align: left;&quot;&gt;Thinking Sphinx (&lt;/span&gt;&lt;span style=&quot;background-color: white; font-size: 14px; line-height: 18px;&quot;&gt;&lt;span style=&quot;font-family: Arial, &#39;Liberation Sans&#39;, &#39;DejaVu Sans&#39;, sans-serif;&quot;&gt;&lt;a href=&quot;http://github.com/freelancing-god/thinking-sphinx&quot;&gt;http://github.com/freelancing-god/thinking-sphinx&lt;/a&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;background-color: white; font-family: Arial, &#39;Liberation Sans&#39;, &#39;DejaVu Sans&#39;, sans-serif; font-size: 14px; line-height: 18px; text-align: left;&quot;&gt;)&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style=&quot;background-color: white; font-family: Arial, &#39;Liberation Sans&#39;, &#39;DejaVu Sans&#39;, sans-serif; font-size: 14px; line-height: 18px; text-align: left;&quot;&gt;Sunspot for Solr (&lt;/span&gt;&lt;span style=&quot;background-color: white; font-size: 14px; line-height: 18px;&quot;&gt;&lt;span style=&quot;font-family: Arial, &#39;Liberation Sans&#39;, &#39;DejaVu Sans&#39;, sans-serif;&quot;&gt;&lt;a href=&quot;http://github.com/outoftime/sunspot&quot;&gt;http://github.com/outoftime/sunspot&lt;/a&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;background-color: white; font-family: Arial, &#39;Liberation Sans&#39;, &#39;DejaVu Sans&#39;, sans-serif; font-size: 14px; line-height: 18px; text-align: left;&quot;&gt;)&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style=&quot;background-color: white; font-family: Arial, &#39;Liberation Sans&#39;, &#39;DejaVu Sans&#39;, sans-serif; text-align: left;&quot;&gt;&lt;span style=&quot;font-size: 14px; line-height: 18px;&quot;&gt;Search Logic (&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;background-color: white; font-size: 14px; line-height: 18px; text-align: left;&quot;&gt;&lt;span style=&quot;font-family: Arial, &#39;Liberation Sans&#39;, &#39;DejaVu Sans&#39;, sans-serif;&quot;&gt;&lt;a href=&quot;http://github.com/railsdog/searchlogic&quot;&gt;http://github.com/railsdog/searchlogic&lt;/a&gt;)&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;b style=&quot;background-color: white;&quot;&gt;Caching:&lt;/b&gt;&lt;br /&gt;
&lt;ol&gt;
&lt;li&gt;&lt;span style=&quot;background-color: white;&quot;&gt;Memcached (&lt;/span&gt;&lt;a href=&quot;http://memcached.org/&quot; style=&quot;background-color: white;&quot;&gt;http://memcached.org/&lt;/a&gt;&lt;span style=&quot;background-color: white;&quot;&gt;)&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style=&quot;background-color: white;&quot;&gt;High performance Memached client - Dalli (&lt;/span&gt;&lt;a href=&quot;https://github.com/mperham/dalli&quot; style=&quot;background-color: white;&quot;&gt;https://github.com/mperham/dalli&lt;/a&gt;&lt;span style=&quot;background-color: white;&quot;&gt;)&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style=&quot;background-color: #fafafa; color: #666666; font-family: Helvetica, arial, freesans, clean, sans-serif; font-size: 13px; line-height: 18px;&quot;&gt;Ruby library for accessing memcached -&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;background-color: white;&quot;&gt;memcache-client (&lt;/span&gt;&lt;a href=&quot;https://github.com/mperham/memcache-client&quot; style=&quot;background-color: white;&quot;&gt;https://github.com/mperham/memcache-client&lt;/a&gt;&lt;span style=&quot;background-color: white;&quot;&gt;)&lt;/span&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;b style=&quot;background-color: white;&quot;&gt;File upload:&lt;/b&gt;&lt;br /&gt;
&lt;ol&gt;
&lt;li&gt;&lt;span style=&quot;background-color: white;&quot;&gt;Paper clip (&lt;a href=&quot;http://github.com/thoughtbot/paperclip&quot;&gt;http://github.com/thoughtbot/paperclip&lt;/a&gt;)&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style=&quot;background-color: white;&quot;&gt;Carrierwave (&lt;a href=&quot;http://github.com/jnicklas/carrierwave&quot;&gt;http://github.com/jnicklas/carrierwave&lt;/a&gt;)&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style=&quot;background-color: white;&quot;&gt;attachment_fu (&lt;a href=&quot;http://github.com/technoweenie/attachment_fu&quot;&gt;http://github.com/technoweenie/attachment_fu&lt;/a&gt;)&amp;nbsp;&lt;/span&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;b style=&quot;background-color: white;&quot;&gt;In-line Text Editor:&lt;/b&gt;&lt;br /&gt;
&lt;ol&gt;
&lt;li&gt;&lt;span style=&quot;background-color: white;&quot;&gt;TinyMCE (&lt;/span&gt;&lt;a href=&quot;https://github.com/spohlenz/tinymce-rails&quot; style=&quot;background-color: white;&quot;&gt;https://github.com/spohlenz/tinymce-rails&lt;/a&gt;&lt;span style=&quot;background-color: white;&quot;&gt;)&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style=&quot;background-color: white;&quot;&gt;Rails ckeditor (&lt;/span&gt;&lt;a href=&quot;https://github.com/galetahub/rails-ckeditor&quot; style=&quot;background-color: white;&quot;&gt;https://github.com/galetahub/rails-ckeditor&lt;/a&gt;&lt;span style=&quot;background-color: white;&quot;&gt;)&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style=&quot;background-color: white;&quot;&gt;Mercury (&lt;/span&gt;&lt;a href=&quot;https://github.com/jejacks0n/mercury&quot; style=&quot;background-color: white;&quot;&gt;https://github.com/jejacks0n/mercury&lt;/a&gt;&lt;span style=&quot;background-color: white;&quot;&gt;)&lt;/span&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;b style=&quot;background-color: white;&quot;&gt;CMS:&lt;/b&gt;&lt;br /&gt;
&lt;ol&gt;
&lt;li&gt;&lt;span style=&quot;background-color: white;&quot;&gt;Refinery CMS (&lt;a href=&quot;http://github.com/resolve/refinerycms&quot;&gt;http://github.com/resolve/refinerycms&lt;/a&gt;)&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style=&quot;background-color: white;&quot;&gt;Locomotive (&lt;a href=&quot;http://github.com/locomotivecms/engine&quot;&gt;http://github.com/locomotivecms/engine&lt;/a&gt;)&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style=&quot;background-color: white;&quot;&gt;Browser CMS (&lt;a href=&quot;http://github.com/browsermedia/browsercms&quot;&gt;http://github.com/browsermedia/browsercms&lt;/a&gt;)&lt;/span&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;b style=&quot;background-color: white;&quot;&gt;Development servers:&lt;/b&gt;&lt;br /&gt;
&lt;ol&gt;
&lt;li&gt;&lt;span style=&quot;background-color: white;&quot;&gt;Webrick (&lt;/span&gt;&lt;a href=&quot;http://www.ruby-doc.org/stdlib-1.9.3/libdoc/webrick/rdoc/index.html&quot; style=&quot;background-color: white;&quot;&gt;http://www.ruby-doc.org/stdlib-1.9.3/libdoc/webrick/rdoc/index.html&lt;/a&gt;&lt;span style=&quot;background-color: white;&quot;&gt;)&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style=&quot;background-color: white;&quot;&gt;Mongrel (&lt;/span&gt;&lt;a href=&quot;http://rubyforge.org/projects/mongrel/&quot; style=&quot;background-color: white;&quot;&gt;http://rubyforge.org/projects/mongrel/&lt;/a&gt;&lt;span style=&quot;background-color: white;&quot;&gt;)&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style=&quot;background-color: white;&quot;&gt;thin (&lt;/span&gt;&lt;a href=&quot;http://code.macournoyer.com/thin/&quot; style=&quot;background-color: white;&quot;&gt;http://code.macournoyer.com/thin/&lt;/a&gt;&lt;span style=&quot;background-color: white;&quot;&gt;)&lt;/span&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;b&gt;Code profiling:&lt;/b&gt;&lt;br /&gt;
&lt;ol&gt;
&lt;li&gt;NewRelic (&lt;a href=&quot;http://www.newrelic.com/ruby&quot;&gt;http://www.newrelic.com/ruby&lt;/a&gt;)&lt;/li&gt;
&lt;li&gt;Rails Analyzer (http://rails-analyzer.rubyforge.org/)&lt;/li&gt;
&lt;li&gt;Rack Bug (&lt;a href=&quot;http://github.com/brynary/rack-bug&quot;&gt;http://github.com/brynary/rack-bug&lt;/a&gt;)&lt;/li&gt;
&lt;/ol&gt;
&lt;b&gt;Code review:&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;ol&gt;
&lt;li&gt;reek (&lt;a href=&quot;https://github.com/troessner/reek&quot;&gt;https://github.com/troessner/reek&lt;/a&gt;)&lt;/li&gt;
&lt;li&gt;Rails best pracises (
&lt;a href=&quot;https://github.com/railsbp/rails_best_practices&quot;&gt;https://github.com/railsbp/rails_best_practices&lt;/a&gt;)&lt;/li&gt;
&lt;li&gt;rcov (
&lt;a href=&quot;https://github.com/relevance/rcov&quot;&gt;https://github.com/relevance/rcov&lt;/a&gt;)&lt;/li&gt;
&lt;/ol&gt;
&lt;br /&gt;
&lt;b style=&quot;background-color: white;&quot;&gt;Database:&lt;/b&gt;&lt;br /&gt;
&lt;ol&gt;
&lt;li&gt;MySQL (
&lt;a href=&quot;http://www.mysql.com/&quot;&gt;http://www.mysql.com/&lt;/a&gt;)&lt;/li&gt;
&lt;li&gt;PostgreSQL (
&lt;a href=&quot;http://www.postgresql.org/&quot;&gt;http://www.postgresql.org/&lt;/a&gt;)&lt;/li&gt;
&lt;li&gt;No SQL Database - MongoDB (
&lt;a href=&quot;http://www.mongodb.org/&quot;&gt;http://www.mongodb.org/&lt;/a&gt;)&amp;nbsp;
with mongoid or data mapper&lt;/li&gt;
&lt;/ol&gt;
&lt;b&gt;XML Parser and Mapper:&lt;/b&gt;&lt;br /&gt;
&lt;ol&gt;
&lt;li&gt;&lt;b&gt;&lt;span style=&quot;font-weight: normal;&quot;&gt;libxml-Ruby (&lt;/span&gt;&lt;/b&gt;
&lt;a href=&quot;https://github.com/xml4r/libxml-ruby&quot;&gt;https://github.com/xml4r/libxml-ruby&lt;/a&gt;)&lt;/li&gt;
&lt;li&gt;&lt;b&gt;&lt;span style=&quot;font-weight: normal;&quot;&gt;Nokogiri (&lt;/span&gt;&lt;/b&gt;
&lt;a href=&quot;http://nokogiri.org/&quot;&gt;http://nokogiri.org/&lt;/a&gt;)&lt;/li&gt;
&lt;li&gt;&lt;b&gt;&lt;span style=&quot;font-weight: normal;&quot;&gt;Happymapper&amp;nbsp;&lt;/span&gt;&lt;/b&gt;&lt;/li&gt;
&lt;ol&gt;
&lt;li&gt;&lt;b&gt;&lt;span style=&quot;font-weight: normal;&quot;&gt;nokogiri-happymapper (&lt;/span&gt;&lt;/b&gt;
&lt;a href=&quot;https://github.com/dam5s/happymapper&quot;&gt;https://github.com/dam5s/happymapper&lt;/a&gt;)&lt;/li&gt;
&lt;li&gt;libxml-ruby happymapper (
&lt;a href=&quot;https://github.com/jnunemaker/happymapper&quot;&gt;https://github.com/jnunemaker/happymapper&lt;/a&gt;&amp;nbsp;)&lt;/li&gt;
&lt;/ol&gt;
&lt;/ol&gt;
&lt;b&gt;Background Jobs:&lt;/b&gt;&lt;br /&gt;
&lt;ol&gt;
&lt;li&gt;&lt;span style=&quot;background-color: white;&quot;&gt;rescue (&lt;a href=&quot;http://github.com/defunkt/resque&quot;&gt;http://github.com/defunkt/resque&lt;/a&gt;)&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;delayed_job (&lt;a href=&quot;https://github.com/collectiveidea/delayed_job/&quot;&gt;https://github.com/collectiveidea/delayed_job/&lt;/a&gt;)&lt;/li&gt;
&lt;li&gt;&lt;span style=&quot;text-align: left;&quot;&gt;&lt;span style=&quot;font-family: Arial, &#39;Liberation Sans&#39;, &#39;DejaVu Sans&#39;, sans-serif;&quot;&gt;&lt;span style=&quot;font-size: 14px; line-height: 18px;&quot;&gt;beanstalkd and stalker (&lt;a href=&quot;http://railscasts.com/episodes/243-beanstalkd-and-stalker&quot;&gt;http://railscasts.com/episodes/243-beanstalkd-and-stalker&lt;/a&gt;)&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;b&gt;Test Frameworks:&lt;/b&gt;&lt;br /&gt;
&lt;ol&gt;
&lt;li&gt;&lt;span style=&quot;background-color: white;&quot;&gt;BDD - Cucumber (&lt;a href=&quot;http://cukes.info/&quot;&gt;http://cukes.info/&lt;/a&gt;)&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style=&quot;background-color: white;&quot;&gt;TDD - Rspec (&lt;a href=&quot;http://rspec.info/&quot;&gt;http://rspec.info/&lt;/a&gt;)&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style=&quot;background-color: white;&quot;&gt;UAT - Selenium (&lt;a href=&quot;http://github.com/paytonrules/selenium-on-rails&quot;&gt;http://github.com/paytonrules/selenium-on-rails&lt;/a&gt;)&lt;/span&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;b style=&quot;background-color: white;&quot;&gt;Web Services:&lt;/b&gt;&lt;br /&gt;
&lt;ol&gt;
&lt;li&gt;&lt;span style=&quot;background-color: white;&quot;&gt;httpparty (&lt;/span&gt;&lt;a href=&quot;http://httparty.rubyforge.org/&quot;&gt;http://httparty.rubyforge.org/&lt;/a&gt;)&lt;/li&gt;
&lt;li&gt;&lt;span style=&quot;background-color: white;&quot;&gt;SOAP client - savon (&lt;/span&gt;&lt;a href=&quot;http://github.com/rubiii/savon&quot;&gt;http://github.com/rubiii/savon&lt;/a&gt;)&lt;/li&gt;
&lt;li&gt;&lt;span style=&quot;background-color: white;&quot;&gt;For testing REST APIs&amp;nbsp;-&amp;nbsp;VCR (&lt;a href=&quot;http://github.com/myronmarston/vcr&quot;&gt;http://github.com/myronmarston/vcr&lt;/a&gt;)&lt;/span&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;b style=&quot;background-color: white;&quot;&gt;Production servers:&lt;/b&gt;&lt;br /&gt;
&lt;ol&gt;
&lt;li&gt;&lt;span style=&quot;background-color: white;&quot;&gt;Apache + Mongrel cluster (&lt;a href=&quot;https://github.com/kyusik/mongrel_cluster&quot;&gt;https://github.com/kyusik/mongrel_cluster&lt;/a&gt;)&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style=&quot;background-color: white;&quot;&gt;Nginx passenger (&lt;/span&gt;
&lt;a href=&quot;http://www.modrails.com/&quot;&gt;http://www.modrails.com/&lt;/a&gt;)&lt;/li&gt;
&lt;li&gt;&lt;span style=&quot;background-color: white;&quot;&gt;Apache Passenger (&lt;a href=&quot;http://www.modrails.com/&quot;&gt;http://www.modrails.com/&lt;/a&gt;)&lt;/span&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;b style=&quot;background-color: white;&quot;&gt;Deployment Scripts:&lt;/b&gt;&lt;br /&gt;
&lt;ol&gt;
&lt;li&gt;Capistrano (&lt;a href=&quot;https://github.com/capistrano/capistrano/wiki&quot;&gt;https://github.com/capistrano/capistrano/wiki&lt;/a&gt;)&lt;/li&gt;
&lt;li&gt;Rubber (&lt;a href=&quot;http://github.com/wr0ngway/rubber&quot;&gt;http://github.com/wr0ngway/rubber&lt;/a&gt;)&lt;/li&gt;
&lt;li&gt;Inploy (&lt;a href=&quot;https://github.com/dcrec1/inploy/&quot;&gt;https://github.com/dcrec1/inploy/&lt;/a&gt;)&lt;/li&gt;
&lt;/ol&gt;
&lt;b style=&quot;background-color: white;&quot;&gt;Continues Integration:&lt;/b&gt;&lt;br /&gt;
&lt;ol&gt;
&lt;li&gt;Integrity (&lt;a href=&quot;https://github.com/integrity/integrity&quot;&gt;https://github.com/integrity/integrity&lt;/a&gt;)&lt;/li&gt;
&lt;li&gt;Cruisecontrol.rb (&lt;a href=&quot;http://cruisecontrolrb.thoughtworks.com/&quot;&gt;http://cruisecontrolrb.thoughtworks.com/&lt;/a&gt;)&lt;/li&gt;
&lt;li&gt;Teamcity (&lt;a href=&quot;http://www.jetbrains.com/teamcity/&quot;&gt;http://www.jetbrains.com/teamcity/&lt;/a&gt;)&lt;/li&gt;
&lt;/ol&gt;
&lt;b style=&quot;background-color: white;&quot;&gt;Exceptions Tracker:&lt;/b&gt;&lt;br /&gt;
&lt;ol&gt;
&lt;li&gt;&lt;span style=&quot;background-color: white;&quot;&gt;Exception Notifier (&lt;/span&gt;&lt;a href=&quot;http://github.com/smartinez87/exception_notification&quot;&gt;http://github.com/smartinez87/exception_notification&lt;/a&gt;)&lt;/li&gt;
&lt;li&gt;Exceptional (&lt;a href=&quot;http://github.com/exceptional/exceptional&quot;&gt;http://github.com/exceptional/exceptional&lt;/a&gt;)&lt;/li&gt;
&lt;li&gt;Exception Logger (&lt;a href=&quot;http://github.com/QuBiT/exception_logger&quot;&gt;http://github.com/QuBiT/exception_logger&lt;/a&gt;)&lt;/li&gt;
&lt;/ol&gt;
&lt;b&gt;Performance monitoring:&lt;/b&gt;&lt;br /&gt;
&lt;ol&gt;
&lt;li&gt;&lt;span style=&quot;background-color: white;&quot;&gt;Newrelic (&lt;a href=&quot;http://newrelic.com/&quot;&gt;http://newrelic.com/&lt;/a&gt;)&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style=&quot;background-color: white;&quot;&gt;Munin (&lt;a href=&quot;http://munin-monitoring.org/&quot;&gt;http://munin-monitoring.org/&lt;/a&gt;)&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style=&quot;background-color: white;&quot;&gt;Scout (&lt;/span&gt;&lt;a href=&quot;https://scoutapp.com/&quot;&gt;https://scoutapp.com/&lt;/a&gt;)&lt;/li&gt;
&lt;/ol&gt;
&lt;span style=&quot;background-color: white;&quot;&gt;&lt;b&gt;Cloud:&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;ol&gt;
&lt;li&gt;&lt;span style=&quot;background-color: white;&quot;&gt;Heroku (&lt;/span&gt;&lt;a href=&quot;http://www.heroku.com/&quot;&gt;http://www.heroku.com/&lt;/a&gt;)&lt;/li&gt;
&lt;li&gt;&lt;span style=&quot;background-color: white;&quot;&gt;Engineyard (&lt;a href=&quot;http://www.engineyard.com/&quot;&gt;http://www.engineyard.com/&lt;/a&gt;)&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style=&quot;background-color: white;&quot;&gt;Amazon aws (&lt;a href=&quot;http://aws.amazon.com/ec2/&quot;&gt;http://aws.amazon.com/ec2/&lt;/a&gt;)&lt;/span&gt;&lt;/li&gt;
&lt;/ol&gt;
</content><link rel='replies' type='application/atom+xml' href='http://rorandme.blogspot.com/feeds/3819634623893663474/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://rorandme.blogspot.com/2012/06/standard-toolbox-for-ruby-on-rails.html#comment-form' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8243723482882736139/posts/default/3819634623893663474'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8243723482882736139/posts/default/3819634623893663474'/><link rel='alternate' type='text/html' href='http://rorandme.blogspot.com/2012/06/standard-toolbox-for-ruby-on-rails.html' title='Standard Toolbox for Ruby on Rails projects'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8243723482882736139.post-4207670930304986750</id><published>2012-06-21T01:19:00.000+05:30</published><updated>2012-06-22T00:37:35.601+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="app/views/layouts"/><category scheme="http://www.blogger.com/atom/ns#" term="application.html.erb"/><category scheme="http://www.blogger.com/atom/ns#" term="content_for"/><category scheme="http://www.blogger.com/atom/ns#" term="layouts"/><category scheme="http://www.blogger.com/atom/ns#" term="nesting layouts"/><category scheme="http://www.blogger.com/atom/ns#" term="Rails"/><category scheme="http://www.blogger.com/atom/ns#" term="rails3"/><category scheme="http://www.blogger.com/atom/ns#" term="rendering"/><category scheme="http://www.blogger.com/atom/ns#" term="Ruby"/><category scheme="http://www.blogger.com/atom/ns#" term="ruby on rails"/><category scheme="http://www.blogger.com/atom/ns#" term="yield"/><title type='text'>Rails 3 and Nesting Layouts</title><content type='html'>Layout plays crucial role in making your pages look beautiful and well connected on the site by holding them together. It acts as central theme and hence it is important to learn what you can do with layouts in rails, one of the most common is nesting the layouts -&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;u&gt;Nesting layouts:&lt;/u&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;u&gt;&lt;br /&gt;&lt;/u&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;First (top) level layout (app/views/layouts/application.html.erb)&lt;/b&gt;&lt;br /&gt;
&lt;pre style=&quot;background-image: URL(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh84Rur_tlUxHWvUnwN2JJsDQ-Uyy9JvqOXY_p4_cT7HKqont4q8xVdk4TOUWzDDV4e8LSyc7K6zv3S5MS6QrBwc9VuYtpq2Nk7ui_DcPWYZK5owfyirSU6IZroaF_NLQ7RuvNLwgeZ3BmD/s320/codebg.gif); background: #f0f0f0; border: 1px dashed #CCCCCC; color: black; font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;&quot;&gt;&lt;code style=&quot;color: black; word-wrap: normal;&quot;&gt; &amp;lt;!DOCTYPE html PUBLIC &quot;-//W3C//DTD HTML 4.01//EN&quot;  
   &quot;http://www.w3.org/TR/html4/strict.dtd&quot;&amp;gt;  
 &amp;lt;html lang=&quot;en&quot;&amp;gt;  
 &amp;lt;head&amp;gt;  
  &amp;lt;meta http-equiv=&quot;content-type&quot; content=&quot;text/html; charset=utf-8&quot;&amp;gt;  
  &amp;lt;title&amp;gt;&amp;lt;%= raw @page_title %&amp;gt;&amp;lt;%= Setting.app_name %&amp;gt;&amp;lt;/title&amp;gt;  
  &amp;lt;%= stylesheet_link_tag &quot;application&quot;,&quot;users&quot;,&quot;asks&quot;,&quot;front&quot;,&quot;facebox&quot; %&amp;gt;  
  &amp;lt;%= csrf_meta_tag %&amp;gt;  
  &amp;lt;%= javascript_include_tag &quot;application&quot;,&quot;asks&quot;,&quot;topics&quot;,&quot;users&quot;,&quot;inbox&quot; %&amp;gt;  
 &amp;lt;/head&amp;gt;  
 &amp;lt;body&amp;gt;  
  &amp;lt;div id=&quot;header&quot;&amp;gt;  
   &amp;lt;div class=&quot;container&quot;&amp;gt;  
    &amp;lt;div class=&quot;sidebar&quot;&amp;gt;  
      ...  
    &amp;lt;/div&amp;gt;  
   &amp;lt;/div&amp;gt;  
  &amp;lt;/div&amp;gt;  
  &amp;lt;div id=&quot;main&quot;&amp;gt;  
     &amp;lt;%= content_for?(:second_level_layout) ? yield(:second_level_layout) : yield %&amp;gt;  
  &amp;lt;/div&amp;gt;  
  &amp;lt;div id=&quot;footer&quot;&amp;gt;  
     ...  
  &amp;lt;/div&amp;gt;  
 &amp;lt;/body&amp;gt;  
 &amp;lt;/html&amp;gt;  
&lt;/code&gt;&lt;/pre&gt;
&lt;br /&gt;
&lt;b style=&quot;background-color: white;&quot;&gt;Second Level Layout (&lt;/b&gt;&lt;b style=&quot;background-color: white;&quot;&gt;app/views/layouts/consumer.html.erb&lt;/b&gt;&lt;b style=&quot;background-color: white;&quot;&gt;)&lt;/b&gt;&lt;br /&gt;
&lt;pre style=&quot;background-image: URL(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh84Rur_tlUxHWvUnwN2JJsDQ-Uyy9JvqOXY_p4_cT7HKqont4q8xVdk4TOUWzDDV4e8LSyc7K6zv3S5MS6QrBwc9VuYtpq2Nk7ui_DcPWYZK5owfyirSU6IZroaF_NLQ7RuvNLwgeZ3BmD/s320/codebg.gif); background: #f0f0f0; border: 1px dashed #CCCCCC; color: black; font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;&quot;&gt;&lt;code style=&quot;color: black; word-wrap: normal;&quot;&gt; &amp;lt;% content_for :second_level_layout do %&amp;gt;  
   ...  
   ...  
 &amp;lt;% end %&amp;gt;  
 &amp;lt;div id=&quot;third_level_container&quot;&amp;gt;  
  &amp;lt;%= content_for?(:third_level_layout) ? yield(:third_level_layout) : yield %&amp;gt;  
 &amp;lt;/div&amp;gt;  
 &amp;lt;%= render :template =&amp;gt; &#39;layouts/application&#39; %&amp;gt;  
&lt;/code&gt;&lt;/pre&gt;
&lt;b style=&quot;background-color: white;&quot;&gt;&lt;br /&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b style=&quot;background-color: white;&quot;&gt;Third Level Layout (&lt;/b&gt;&lt;b style=&quot;background-color: white;&quot;&gt;app/views/layouts/billing.html.erb&lt;/b&gt;&lt;b style=&quot;background-color: white;&quot;&gt;)&lt;/b&gt;&lt;br /&gt;
&lt;pre style=&quot;background-image: URL(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh84Rur_tlUxHWvUnwN2JJsDQ-Uyy9JvqOXY_p4_cT7HKqont4q8xVdk4TOUWzDDV4e8LSyc7K6zv3S5MS6QrBwc9VuYtpq2Nk7ui_DcPWYZK5owfyirSU6IZroaF_NLQ7RuvNLwgeZ3BmD/s320/codebg.gif); background: #f0f0f0; border: 1px dashed #CCCCCC; color: black; font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;&quot;&gt;&lt;code style=&quot;color: black; word-wrap: normal;&quot;&gt; &amp;lt;% content_for :third_level_layout do %&amp;gt;  
   ...  
   ...  
 &amp;lt;% end %&amp;gt;  
 &amp;lt;div id=&quot;fourth_level_container&quot;&amp;gt;  
  &amp;lt;%= content_for?(:fourth_level_layout) ? yield(:fourth_level_layout) : yield %&amp;gt;  
 &amp;lt;/div&amp;gt;  
 &amp;lt;%= render :template =&amp;gt; &#39;layouts/consumer&#39; %&amp;gt;  
&lt;/code&gt;&lt;/pre&gt;
&lt;br /&gt;
&lt;b&gt;&lt;i&gt;This can go upto the nth level and you can continue nesting one layout inside another.
&lt;/i&gt;&lt;/b&gt;</content><link rel='replies' type='application/atom+xml' href='http://rorandme.blogspot.com/feeds/4207670930304986750/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://rorandme.blogspot.com/2012/06/rails-3-nesting-layouts.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8243723482882736139/posts/default/4207670930304986750'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8243723482882736139/posts/default/4207670930304986750'/><link rel='alternate' type='text/html' href='http://rorandme.blogspot.com/2012/06/rails-3-nesting-layouts.html' title='Rails 3 and Nesting Layouts'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total><georss:featurename>Pune, Maharashtra, India</georss:featurename><georss:point>18.5204303 73.8567437</georss:point><georss:box>16.604701300000002 71.3298882 20.4361593 76.383599199999992</georss:box></entry><entry><id>tag:blogger.com,1999:blog-8243723482882736139.post-612138906144719199</id><published>2012-05-31T01:49:00.003+05:30</published><updated>2012-06-14T01:23:56.504+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="accordion"/><category scheme="http://www.blogger.com/atom/ns#" term="ajax"/><category scheme="http://www.blogger.com/atom/ns#" term="CRUD"/><category scheme="http://www.blogger.com/atom/ns#" term="expandable"/><category scheme="http://www.blogger.com/atom/ns#" term="JQuery"/><category scheme="http://www.blogger.com/atom/ns#" term="jquery ui"/><category scheme="http://www.blogger.com/atom/ns#" term="one at a time"/><category scheme="http://www.blogger.com/atom/ns#" term="Rails"/><category scheme="http://www.blogger.com/atom/ns#" term="rails3"/><category scheme="http://www.blogger.com/atom/ns#" term="Ruby"/><category scheme="http://www.blogger.com/atom/ns#" term="ruby on rails"/><category scheme="http://www.blogger.com/atom/ns#" term="section"/><category scheme="http://www.blogger.com/atom/ns#" term="ui-state-active"/><category scheme="http://www.blogger.com/atom/ns#" term="ui-state-default"/><category scheme="http://www.blogger.com/atom/ns#" term="ui.core.js"/><title type='text'>Rails 3 and JQuery Accordion</title><content type='html'>I got a chance to integrate JQuery accordion pane with one of my Rails 3 project. &amp;nbsp;Here are my learnings -&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;u&gt;Why accordion pane?&lt;/u&gt;&lt;/b&gt;&lt;br /&gt;
&lt;ol&gt;
&lt;li&gt;You can create a menu. Normally you see accordion menus in left panel of the web page.&amp;nbsp;&lt;/li&gt;
&lt;li&gt;Can be used when you want to show the list of items one expanded at a time. For e.g. product listing, forums etc...&lt;/li&gt;
&lt;li&gt;You can even use it to make photo album.&amp;nbsp;&lt;/li&gt;
&lt;/ol&gt;
&lt;b&gt;&lt;u&gt;How to go about implementing it ?&amp;nbsp;&lt;/u&gt;&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Step 1: Make sure you have required JQuery&amp;nbsp;included in layout of your rails project.&lt;/b&gt;&lt;br /&gt;
Add following lines in layout of your Rails project
&lt;br /&gt;
&lt;pre style=&quot;background-image: URL(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh84Rur_tlUxHWvUnwN2JJsDQ-Uyy9JvqOXY_p4_cT7HKqont4q8xVdk4TOUWzDDV4e8LSyc7K6zv3S5MS6QrBwc9VuYtpq2Nk7ui_DcPWYZK5owfyirSU6IZroaF_NLQ7RuvNLwgeZ3BmD/s320/codebg.gif); background: #f0f0f0; border: 1px dashed #CCCCCC; color: black; font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;&quot;&gt;&lt;b&gt;&lt;code style=&quot;color: black; word-wrap: normal;&quot;&gt; &amp;lt;%= javascript_include_tag &quot;jquery.ui.core.min&quot; %&amp;gt;  
 &amp;lt;%= javascript_include_tag &quot;jquery.ui.widget.min&quot; %&amp;gt;  
 &amp;lt;%= javascript_include_tag &quot;jquery.effects.core&quot; %&amp;gt;  
&lt;/code&gt;&lt;/b&gt;&lt;/pre&gt;
&lt;br /&gt;
Also in your application.js you should have following line in the top section where you find other include.
&lt;br /&gt;
&lt;pre style=&quot;background-image: URL(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh84Rur_tlUxHWvUnwN2JJsDQ-Uyy9JvqOXY_p4_cT7HKqont4q8xVdk4TOUWzDDV4e8LSyc7K6zv3S5MS6QrBwc9VuYtpq2Nk7ui_DcPWYZK5owfyirSU6IZroaF_NLQ7RuvNLwgeZ3BmD/s320/codebg.gif); background: #f0f0f0; border: 1px dashed #CCCCCC; color: black; font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;&quot;&gt;&lt;b&gt;&lt;code style=&quot;color: black; word-wrap: normal;&quot;&gt; //= require jquery-ui  
&lt;/code&gt;&lt;/b&gt;&lt;/pre&gt;
&lt;br /&gt;
I spent 2 hours fixing this one. It was giving me and error &quot;accordion is not a function&quot;. A good way to check whether all required&amp;nbsp;JavaScript&amp;nbsp;is loaded or not is to try following in the Firebug console
&lt;br /&gt;
&lt;pre style=&quot;background-color: #f0f0f0; background-position: initial initial; background-repeat: initial initial; border: 1px dashed rgb(204, 204, 204); color: black; font-family: arial; font-size: 12px; font-weight: bold; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;&quot;&gt;&lt;code style=&quot;color: black; word-wrap: normal;&quot;&gt; &amp;gt; $.widget  
 function  
&lt;/code&gt;&lt;/pre&gt;
&lt;pre style=&quot;background-color: #f0f0f0; background-position: initial initial; background-repeat: initial initial; border: 1px dashed rgb(204, 204, 204); color: black; font-family: arial; font-size: 12px; font-weight: bold; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;&quot;&gt;&lt;code style=&quot;color: black; word-wrap: normal;&quot;&gt; &amp;gt; $().accordion()  
 []  
&lt;/code&gt;&lt;/pre&gt;
&lt;div style=&quot;font-weight: bold;&quot;&gt;
&lt;br /&gt;
&lt;b&gt;Step 2: Dynamically convert make your div to an accordion.&amp;nbsp;&lt;/b&gt;&lt;/div&gt;
&lt;div&gt;
In your js.erb file add following&amp;nbsp;JavaScript&amp;nbsp;code&amp;nbsp;&lt;/div&gt;
&lt;pre style=&quot;background-color: #f0f0f0; background-position: initial initial; background-repeat: initial initial; border: 1px dashed rgb(204, 204, 204); color: black; font-family: arial; font-size: 12px; font-weight: bold; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;&quot;&gt;&lt;code style=&quot;color: black; word-wrap: normal;&quot;&gt; $(function() {   
      $( &quot;#menu&quot; ).accordion({header : &#39;.menu_header&#39;});  
 });  
&lt;/code&gt;&lt;/pre&gt;
&lt;div&gt;
&lt;div style=&quot;font-weight: bold;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
JQuery looks for all the divs with class &#39;menu-header&#39; inside the div with id &quot;menu&quot; and makes them all the expandable sections of the accordion. You can put any JQuery selector to define headers. &amp;nbsp;By default only one section is expandable and others are closed.&amp;nbsp;&lt;/div&gt;
&lt;div style=&quot;font-weight: bold;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;font-weight: bold;&quot;&gt;
&lt;b&gt;Step 3: Dynamically load content into accordion section when created or changed.&lt;/b&gt;&lt;/div&gt;
&lt;pre style=&quot;background-color: #f0f0f0; background-position: initial initial; background-repeat: initial initial; border: 1px dashed rgb(204, 204, 204); color: black; font-family: arial; font-size: 12px; font-weight: bold; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;&quot;&gt;&lt;code style=&quot;color: black; word-wrap: normal;&quot;&gt; var loadContent = function (clicked) {  
     $.ajax({  
       type: &#39;GET&#39;,  
       url: &#39;/catalogue/&#39; + clicked + &#39;/items&#39;,  
       data: &#39;category_id=&amp;lt;%= @category.id %&amp;gt;&#39;  
     })  
   };  
 $(function () {  
   $(&quot;#menu&quot;).accordion({  
     autoHeight: false,  
     header: &#39;.menu_header&#39;,  
     /* create gets called after accordion is created .. means first time.*/  
     create: function (event, ui) {  
      /* Following line is used to find id of a selected catalogue. Catalogue id is set as id of the &quot;menu_header&quot; div.  
        Accordion appends &#39;ui-state-active&#39; class to selected(aka currently active) accordion section.*/  
       var clicked = $(this).find(&#39;.ui-state-active&#39;).attr(&#39;id&#39;);  
      /* Sometime accordion keeps the class &#39;ui-state-default&#39; even after making it active and   
        appending &#39;ui-state-active&#39; class so need to remove it if its active. Following line does that thing */  
       $(this).find(&#39;.ui-state-active&#39;).removeClass(&#39;ui-state-default&#39;);  
       loadContent(clicked);  
     },  
     /* chage gets called every time you click the other expandable section to open it.*/  
     change: function (event, ui) {  
       var clicked = $(this).find(&#39;.ui-state-active&#39;).attr(&#39;id&#39;);  
       loadContent(clicked);  
     }  
   });  
 });  
&lt;/code&gt;&lt;/pre&gt;
&lt;br /&gt;
&lt;b style=&quot;font-weight: bold;&quot;&gt;Step 4: Remove the section from the accordion.&lt;/b&gt;

&lt;br /&gt;
&lt;div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: &#39;Times New Roman&#39;;&quot;&gt;&lt;span style=&quot;white-space: normal;&quot;&gt;If you are using ajax to remove the expandable section from the accordion then following can be one way to do that &lt;b&gt;-&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;b&gt;
&lt;/b&gt;&lt;br /&gt;
&lt;pre style=&quot;background-color: #f0f0f0; background-position: initial initial; background-repeat: initial initial; border: 1px dashed rgb(204, 204, 204); color: black; font-family: arial; font-size: 12px; font-weight: bold; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;&quot;&gt;&lt;code style=&quot;color: black; word-wrap: normal;&quot;&gt; $(&quot;#catalogue_&amp;lt;%= @catalogue.id %&amp;gt;&quot;).remove();  
 /* Following line expands the first section from accordion */  
 $( &quot;#menu&quot; ).accordion({ active: $(&#39;#menu div:first-child&#39;) });  
 /* Show message if no sections present in the accordion */  
 if($(&#39;div.ui-state-default,div.ui-state-active&#39;).size() == 0) {  
   $( &quot;#menu&quot; ).html(&#39;No catalogues found!&#39;).css(&#39;text-align&#39;,&#39;center&#39;);  
 }  
&lt;/code&gt;&lt;/pre&gt;
&lt;b&gt;
&lt;/b&gt;&lt;br /&gt;
&lt;div style=&quot;font-weight: bold;&quot;&gt;
&lt;span style=&quot;font-family: &#39;Times New Roman&#39;;&quot;&gt;&lt;span style=&quot;white-space: normal;&quot;&gt;&lt;b&gt;Step 5: Update the section in the accordion.&amp;nbsp;&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;b&gt;
&lt;/b&gt;&lt;br /&gt;
&lt;div style=&quot;font-weight: bold;&quot;&gt;
&lt;span style=&quot;font-family: &#39;Times New Roman&#39;;&quot;&gt;&lt;span style=&quot;white-space: normal;&quot;&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: &#39;Times New Roman&#39;;&quot;&gt;&lt;span style=&quot;white-space: normal;&quot;&gt;Give id to the divs where you write the section title and content so you are not required to replace the entire accordion section instead you can just update the content using JQuery.&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;b&gt;
&lt;/b&gt;&lt;br /&gt;
&lt;pre style=&quot;background-color: #f0f0f0; background-position: initial initial; background-repeat: initial initial; border: 1px dashed rgb(204, 204, 204); color: black; font-family: arial; font-size: 12px; font-weight: bold; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;&quot;&gt;&lt;code style=&quot;color: black; word-wrap: normal;&quot;&gt; $(&#39;#catalogue_&amp;lt;%= @catalogue.id %&amp;gt;_desc&#39;).html(&quot;&amp;lt;%= @catalogue.description %&amp;gt;&quot;);  
&lt;/code&gt;&lt;/pre&gt;
&lt;b&gt;
&lt;/b&gt;&lt;br /&gt;
&lt;div&gt;
&lt;div style=&quot;font-weight: bold;&quot;&gt;
&lt;span style=&quot;font-family: &#39;Times New Roman&#39;; white-space: normal;&quot;&gt;&lt;b&gt;Step 6: Activate specific section of accordion based on the parameters passed in the URL&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-weight: bold;&quot;&gt;
&lt;span style=&quot;font-family: &#39;Times New Roman&#39;; white-space: normal;&quot;&gt;&lt;b&gt;
&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-weight: bold;&quot;&gt;
&lt;span style=&quot;font-family: &#39;Times New Roman&#39;;&quot;&gt;&lt;span style=&quot;white-space: normal;&quot;&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: &#39;Times New Roman&#39;;&quot;&gt;&lt;span style=&quot;white-space: normal;&quot;&gt;
&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Times New Roman&#39;;&quot;&gt;&lt;span style=&quot;white-space: normal;&quot;&gt;Use this&amp;nbsp;JavaScript&amp;nbsp;and&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;pre style=&quot;background-color: #f0f0f0; background-position: initial initial; background-repeat: initial initial; border: 1px dashed rgb(204, 204, 204); color: black; font-family: arial; font-size: 12px; font-weight: bold; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;&quot;&gt;&lt;code style=&quot;color: black; word-wrap: normal;&quot;&gt; function getAccordionIndex(accordion,matched_element_id){  
   var index = 0;  
   if(matched_element_id != &#39;&#39; &amp;amp;&amp;amp; matched_element_id != &#39;undefined&#39; &amp;amp;&amp;amp; matched_element_id!= null){  
     var matched_element = document.getElementById(matched_element_id);  
     index = $(&#39;#&#39; + accordion + &#39; .ui-accordion-header&#39;).index(matched_element);  
   }  
   return index;  
 }  
&lt;/code&gt;&lt;/pre&gt;
&lt;div style=&quot;font-weight: bold;&quot;&gt;
&lt;span style=&quot;font-family: &#39;Times New Roman&#39;;&quot;&gt;&lt;span style=&quot;white-space: normal;&quot;&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-weight: bold;&quot;&gt;
&lt;span style=&quot;font-family: &#39;Times New Roman&#39;; white-space: normal;&quot;&gt;
&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-weight: bold;&quot;&gt;
&lt;span style=&quot;font-family: &#39;Times New Roman&#39;; white-space: normal;&quot;&gt;
&lt;/span&gt;&lt;/div&gt;
&lt;span style=&quot;font-family: &#39;Times New Roman&#39;; white-space: normal;&quot;&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Times New Roman&#39;; white-space: normal;&quot;&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Times New Roman&#39;; white-space: normal;&quot;&gt;Look at the line no. 13 in following code snippet. It expands the specific section in the accordion provided that you have provided item id as div id for the header divs&lt;/span&gt;&lt;/div&gt;
&lt;pre style=&quot;background-color: #f0f0f0; background-position: initial initial; background-repeat: initial initial; border: 1px dashed rgb(204, 204, 204); color: black; font-family: arial; font-size: 12px; font-weight: bold; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;&quot;&gt;&lt;code style=&quot;color: black; word-wrap: normal;&quot;&gt;1:  var loadContent = function(clicked){  
2:  $.ajax({  
3:          type: &#39;GET&#39;,  
4:          url: &#39;/catalogue/&#39; + clicked + &#39;/items&#39;,  
5:          data: &#39;category_id=&amp;lt;%= @category.id %&amp;gt;&#39;  
6:       })  
7:  };  
8:  $(function() {  
9:  $( &quot;#menu&quot; ).accordion({ autoHeight: false,  
10:  header : &#39;.menu_header&#39;,  
11:  /* create gets called after accordion is created .. means first time.*/  
12:  create: function(event, ui){  
13:  $( &quot;#menu&quot; ).accordion({active: getAccordionIndex(&#39;menu&#39;,&#39;&amp;lt;%=params[:catalogue_id]%&amp;gt;&#39;)});  
14:  /* Following line is used to find id of a selected catalogue. Catalogue id is set as id of the &quot;menu_header&quot; div.  
15:  Accordion appends &#39;ui-state-active&#39; class to selected(aka currently active) accordion section.   
16:   */  
17:  var clicked = $(this).find(&#39;.ui-state-active&#39;).attr(&#39;id&#39;);  
18:  /* Sometime accordion keeps the class &#39;ui-state-default&#39; even after making it active and appending &#39;ui-state-active&#39; class so need to remove it if its active. Following line does that thing */  
19:  $(this).find(&#39;.ui-state-active&#39;).removeClass(&#39;ui-state-default&#39;);  
20:  loadContent (clicked);  
21:  },  
22:  /* chage gets called every time you click the other expandable section to open it.*/  
23:  change: function(event, ui){  
24:  var clicked = $(this).find(&#39;.ui-state-active&#39;).attr(&#39;id&#39;);  
25:  loadContent (clicked);  
26:  }  
27:  });  
28:  });  
&lt;/code&gt;&lt;/pre&gt;
&lt;b&gt;
&lt;/b&gt;&lt;br /&gt;
&lt;div style=&quot;font-weight: bold;&quot;&gt;
&lt;b style=&quot;font-family: &#39;Times New Roman&#39;; white-space: normal;&quot;&gt;&lt;u&gt;Other Interesting Resources&lt;/u&gt;&lt;/b&gt;&lt;br /&gt;
&lt;ol&gt;
&lt;li&gt;&lt;a href=&quot;http://jqueryui.com/demos/accordion/&quot;&gt;http://jqueryui.com/demos/accordion/&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://www.dynamicdrive.com/dynamicindex17/ddaccordion.htm&quot;&gt;http://www.dynamicdrive.com/dynamicindex17/ddaccordion.htm&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://docs.jquery.com/UI/Accordion&quot;&gt;http://docs.jquery.com/UI/Accordion&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://jquery.bassistance.de/accordion/demo/?p=1.1.1&quot;&gt;http://jquery.bassistance.de/accordion/demo/?p=1.1.1&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://www.learningjquery.com/2007/03/accordion-madness&quot;&gt;http://www.learningjquery.com/2007/03/accordion-madness&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://viralpatel.net/blogs/2009/09/create-accordion-menu-jquery.html&quot;&gt;http://viralpatel.net/blogs/2009/09/create-accordion-menu-jquery.html&lt;/a&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;/div&gt;
&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://rorandme.blogspot.com/feeds/612138906144719199/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://rorandme.blogspot.com/2012/05/rails-3-and-jquery-accordion.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8243723482882736139/posts/default/612138906144719199'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8243723482882736139/posts/default/612138906144719199'/><link rel='alternate' type='text/html' href='http://rorandme.blogspot.com/2012/05/rails-3-and-jquery-accordion.html' title='Rails 3 and JQuery Accordion'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total><georss:featurename>Pune, Maharashtra, India</georss:featurename><georss:point>18.5204303 73.8567437</georss:point><georss:box>18.3999798 73.6988152 18.6408808 74.014672199999993</georss:box></entry><entry><id>tag:blogger.com,1999:blog-8243723482882736139.post-719233616211151872</id><published>2012-04-10T00:30:00.001+05:30</published><updated>2012-04-10T00:30:15.372+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="assembla"/><category scheme="http://www.blogger.com/atom/ns#" term="bitbucket"/><category scheme="http://www.blogger.com/atom/ns#" term="code"/><category scheme="http://www.blogger.com/atom/ns#" term="free"/><category scheme="http://www.blogger.com/atom/ns#" term="git"/><category scheme="http://www.blogger.com/atom/ns#" term="github"/><category scheme="http://www.blogger.com/atom/ns#" term="host"/><category scheme="http://www.blogger.com/atom/ns#" term="mercurial"/><category scheme="http://www.blogger.com/atom/ns#" term="opensource"/><category scheme="http://www.blogger.com/atom/ns#" term="private"/><category scheme="http://www.blogger.com/atom/ns#" term="public"/><category scheme="http://www.blogger.com/atom/ns#" term="Rails"/><category scheme="http://www.blogger.com/atom/ns#" term="repository"/><category scheme="http://www.blogger.com/atom/ns#" term="Ruby"/><category scheme="http://www.blogger.com/atom/ns#" term="ruby on rails"/><category scheme="http://www.blogger.com/atom/ns#" term="source code"/><category scheme="http://www.blogger.com/atom/ns#" term="svn"/><category scheme="http://www.blogger.com/atom/ns#" term="version control"/><title type='text'>Free Private Source Code Repository For Ruby on Rails</title><content type='html'>There are many people who want to try out their new project idea in Ruby On Rails. Usually they are a team of 2-3 people, sometimes geographically apart.&amp;nbsp;When you start over, first thing that you need is source code repository where you can put your code so that it is secure and shared effectively across. And&amp;nbsp;off course&amp;nbsp;private.&lt;br /&gt;
&lt;br /&gt;
At start, most of the time you have no money and you start looking for something free and easy. First name comes to the mind is github(github.com). Its indeed the best one but it asks you to pay money if you want to make your repository private. The micro plan is also about $7 per month. Which might not be affordable on inception. So I did a little check and sharing my findings with you -&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;ol&gt;
&lt;li&gt;Assembla (
&lt;a href=&quot;http://www.assembla.com/&quot;&gt;http://www.assembla.com&lt;/a&gt;)- Its gives one free private repository with 1GB space (SVN or Git) For unlimited users.&lt;/li&gt;
&lt;li&gt;Bitbucket (https://bitbucket.org) - It gives&amp;nbsp;unlimited public &amp;amp; private repositories for 5 users. (Git or Mercurial).&amp;nbsp;&lt;/li&gt;
&lt;li&gt;Beanstalk (
&lt;a href=&quot;http://beanstalkapp.com/&quot;&gt;http://beanstalkapp.com/&lt;/a&gt;&amp;nbsp;) - It gives 100 MB Storage, 1 User, 1 Repository.&lt;/li&gt;
&lt;li&gt;ProjectLocker (
&lt;a href=&quot;http://www.projectlocker.com/&quot;&gt;http://www.projectlocker.com/&lt;/a&gt;) - It gives free SVN or Git for 3 users , 300 MB&lt;/li&gt;
&lt;li&gt;Unfuddle (&amp;nbsp;&lt;a href=&quot;http://unfuddle.com/&quot;&gt;http://unfuddle.com&lt;/a&gt;) - It gives free SVN 2 people 200 MB&lt;/li&gt;
&lt;/ol&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
Though I have listed 5 repositories I&amp;nbsp;recommend&amp;nbsp;Assembla and Bitbucket. They are very professional and quite straight forward. I have used Bitbucket my self and I do not see any problem with it.&amp;nbsp;If you have money then github is the best and most popular choice.&amp;nbsp;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
If you want to opensource your code then you need not worry about anything, almost all the online code repository allows to create opensource projects for free.&amp;nbsp;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://rorandme.blogspot.com/feeds/719233616211151872/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://rorandme.blogspot.com/2012/04/free-private-source-code-repository-for.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8243723482882736139/posts/default/719233616211151872'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8243723482882736139/posts/default/719233616211151872'/><link rel='alternate' type='text/html' href='http://rorandme.blogspot.com/2012/04/free-private-source-code-repository-for.html' title='Free Private Source Code Repository For Ruby on Rails'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total><georss:featurename>Pune, Maharashtra, India</georss:featurename><georss:point>18.5204303 73.8567437</georss:point><georss:box>18.3999798 73.6988152 18.6408808 74.014672199999993</georss:box></entry><entry><id>tag:blogger.com,1999:blog-8243723482882736139.post-7945558959529676989</id><published>2012-03-04T21:08:00.002+05:30</published><updated>2012-03-04T21:08:31.802+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="escape"/><category scheme="http://www.blogger.com/atom/ns#" term="h"/><category scheme="http://www.blogger.com/atom/ns#" term="h()"/><category scheme="http://www.blogger.com/atom/ns#" term="html safe"/><category scheme="http://www.blogger.com/atom/ns#" term="html_escape"/><category scheme="http://www.blogger.com/atom/ns#" term="injection"/><category scheme="http://www.blogger.com/atom/ns#" term="output_safety"/><category scheme="http://www.blogger.com/atom/ns#" term="Rails"/><category scheme="http://www.blogger.com/atom/ns#" term="rails3"/><category scheme="http://www.blogger.com/atom/ns#" term="raw"/><category scheme="http://www.blogger.com/atom/ns#" term="Ruby"/><category scheme="http://www.blogger.com/atom/ns#" term="secure"/><title type='text'>The raw and h() in the Rails</title><content type='html'>We always want to secure our Rails application to protect it from the attacks. The most basic thing which we do is to make the content html safe so nobody can inject malicious code or JavaScript into it.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;But what is exactly meant by making the content html safe ?&amp;nbsp;&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
Normally we all use h() method in Rails 2.x to do this. But hardly we bother to look into the method&amp;nbsp;definition&amp;nbsp;to find what is does exactly.&lt;br /&gt;
&lt;br /&gt;
h() is like shorthand for the method html_escape. Look at the snippet from -&lt;br /&gt;
&lt;br /&gt;
&lt;i&gt;rails/activesupport/lib/active_support/core_ext/string/output_safety.rb&lt;/i&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
class ERB&lt;br /&gt;
&amp;nbsp; module Util&lt;br /&gt;
&amp;nbsp; &amp;nbsp;&amp;nbsp;HTML_ESCAPE = { &#39;&amp;amp;&#39; =&amp;gt; &#39;&amp;amp;amp;&#39;, &amp;nbsp;&#39;&amp;gt;&#39; =&amp;gt; &#39;&amp;amp;gt;&#39;, &amp;nbsp; &#39;&amp;lt;&#39; =&amp;gt; &#39;&amp;amp;lt;&#39;, &#39;&quot;&#39; =&amp;gt; &#39;&amp;amp;quot;&#39; }&lt;br /&gt;
&amp;nbsp; &amp;nbsp; remove_method(:h)&lt;br /&gt;
&amp;nbsp; &amp;nbsp; alias h html_escape&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; &amp;nbsp; def html_escape(s) #:nodoc:&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; s = s.to_s&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; if s.html_safe?&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; s&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; else&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;b&gt;s.gsub(/[&amp;amp;&quot;&amp;gt;&amp;lt;]/n) { |special| HTML_ESCAPE[special] }&lt;/b&gt;.html_safe&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; end&lt;br /&gt;
&amp;nbsp; &amp;nbsp; end&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The important thing to notice here is that the characters are replaced based on the HTML_ESCAPE hash provided above. This way those characters will not be rendered as HTML but still they look same on web page.&lt;br /&gt;
&lt;br /&gt;
E.g. If you write &quot;&amp;amp;lt;div&amp;amp;gt;Hello!&amp;amp;lt;/div&amp;amp;gt;&quot; in a file and save it with .html extension. Open the same with your browser. And you will see that the browser will print it as &quot;&amp;lt;div&amp;gt;Hello!&amp;lt;/div&amp;gt;&quot; instead of creating a div or printing it as &quot;&amp;amp;lt;div&amp;amp;gt;Hello!&amp;amp;lt;/div&amp;amp;gt;&quot;. This is the magic of h() method. These replacement character sequences (e.g. &amp;amp;lt; etc...) are called HTML named special&amp;nbsp;entity&amp;nbsp;references. There are only few of them. You can find it &lt;a href=&quot;http://www.w3.org/TR/html4/charset.html#h-5.3.2&quot; target=&quot;_blank&quot;&gt;here&lt;/a&gt;.&lt;br /&gt;
&lt;br /&gt;
This behaviour of making the content html safe is changed a little bit in Rails 3. Previously everything was unsafe by default and we had to use h() to make it safe. But with Rails 3 everything is safe by default and we are required to use &quot;raw&quot; if we want to get it rendered as HTML on browser instead of plain text.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;One&amp;nbsp;interesting&amp;nbsp;problem related to this:&lt;/b&gt;&lt;br /&gt;
In Rails 3, render the user comment in such a way that any script or code entered by user should be rendered as text but links should be rendered as HTML.&lt;br /&gt;
&lt;br /&gt;
Quick Solution:&lt;br /&gt;
&amp;lt;% display_comment=@user.comment.gsub(/&amp;lt;([^a])/,&#39;&amp;amp;lt;\1&#39;).gsub(/&amp;lt;\/([^a])/,&#39;&amp;amp;lt;/\1&#39;)%&amp;gt;&lt;br /&gt;
&amp;lt;%= raw display_comment %&amp;gt;</content><link rel='replies' type='application/atom+xml' href='http://rorandme.blogspot.com/feeds/7945558959529676989/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://rorandme.blogspot.com/2012/03/raw-and-h-in-rails.html#comment-form' title='4 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8243723482882736139/posts/default/7945558959529676989'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8243723482882736139/posts/default/7945558959529676989'/><link rel='alternate' type='text/html' href='http://rorandme.blogspot.com/2012/03/raw-and-h-in-rails.html' title='The raw and h() in the Rails'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>4</thr:total><georss:featurename>Pune, Maharashtra, India</georss:featurename><georss:point>18.5204303 73.8567437</georss:point><georss:box>18.3999798 73.6988152 18.6408808 74.014672199999993</georss:box></entry><entry><id>tag:blogger.com,1999:blog-8243723482882736139.post-1148400951812314951</id><published>2012-02-28T16:41:00.000+05:30</published><updated>2012-06-14T01:34:52.958+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="builder"/><category scheme="http://www.blogger.com/atom/ns#" term="decorator"/><category scheme="http://www.blogger.com/atom/ns#" term="design pattern"/><category scheme="http://www.blogger.com/atom/ns#" term="director"/><category scheme="http://www.blogger.com/atom/ns#" term="examples"/><category scheme="http://www.blogger.com/atom/ns#" term="module"/><category scheme="http://www.blogger.com/atom/ns#" term="Ruby"/><category scheme="http://www.blogger.com/atom/ns#" term="singleton"/><title type='text'>Some simple design patterns in Ruby with examples</title><content type='html'>&lt;b&gt;1. Singleton pattern&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
Returns the same object every time. Can be used to represent&lt;br /&gt;
&lt;ul&gt;
&lt;li&gt;Printer Object in your application (classic example)&lt;/li&gt;
&lt;li&gt;Application wide counter to keep track of your records (Common Serial No. for different type of assets)&lt;/li&gt;
&lt;/ul&gt;
General idea is to make the initializer/constructor private so no body can call it directly.&amp;nbsp; And then rewrite it to create the object only if it doesn&#39;t exist otherwise return the existing object. Normally the instance is stored in some instance variable.&lt;br /&gt;
&lt;pre style=&quot;background-image: URL(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh84Rur_tlUxHWvUnwN2JJsDQ-Uyy9JvqOXY_p4_cT7HKqont4q8xVdk4TOUWzDDV4e8LSyc7K6zv3S5MS6QrBwc9VuYtpq2Nk7ui_DcPWYZK5owfyirSU6IZroaF_NLQ7RuvNLwgeZ3BmD/s320/codebg.gif); background: #f0f0f0; border: 1px dashed #CCCCCC; color: black; font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;&quot;&gt;&lt;code style=&quot;color: black; word-wrap: normal;&quot;&gt; require &#39;singleton&#39;  
 class Base  
  include Singleton  
 end  
 Base.new # Error =&amp;gt; private method `new&#39; called for Base:Class (NoMethodError)  
 b1 = Base.instance  
 p b1.object_id # Output =&amp;gt; 21128892  
 b2 = Base.instance  
 p b2.object_id # Output =&amp;gt; 21128892  
&lt;/code&gt;&lt;/pre&gt;
&lt;br /&gt;
&lt;b&gt;2. Decorator pattern&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
Allows you to freely choose the decoration and add it on to your base. Can be used to represent&lt;br /&gt;
&lt;ul&gt;
&lt;li&gt;Subscription based model where there are lot of add-ons&lt;/li&gt;
&lt;li&gt;Products with lot of add on features. e.g. Mobile phones have many additional features like camera, headset etc.. &lt;/li&gt;
&lt;/ul&gt;
Generic idea is to store the decorated object as instance variable and use method missing to provide generic interface to call the methods which are common on the decorated object like cost, quantity, size etc..&lt;br /&gt;
&lt;pre style=&quot;background-image: URL(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh84Rur_tlUxHWvUnwN2JJsDQ-Uyy9JvqOXY_p4_cT7HKqont4q8xVdk4TOUWzDDV4e8LSyc7K6zv3S5MS6QrBwc9VuYtpq2Nk7ui_DcPWYZK5owfyirSU6IZroaF_NLQ7RuvNLwgeZ3BmD/s320/codebg.gif); background: #f0f0f0; border: 1px dashed #CCCCCC; color: black; font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;&quot;&gt;&lt;code style=&quot;color: black; word-wrap: normal;&quot;&gt; module Decorator  
  def initialize decorated  
   @decorated = decorated  
  end   
  def method_missing(method, *args)  
   @decorated.send(method, *args) if @decorated.respond_to?(method)  
  end  
 end  
 class BaseSubscriptionPlan    
  def features  
   [:free_talktime,:free_sms]  
  end   
 end  
 class ISDAddOnPack  
  include Decorator   
  def features  
   @decorated.features + [:free_isd_time]  
  end   
 end  
 p BaseSubscriptionPlan.new.features # Output =&amp;gt; [:free_talktime, :free_sms]  
 p ISDAddOnPack.new(BaseSubscriptionPlan.new).features # Output =&amp;gt; [:free_talktime, :free_sms, :free_isd_time]  
&lt;/code&gt;&lt;/pre&gt;
&lt;br /&gt;
&lt;b&gt;3. Builder pattern&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;br /&gt;
Allows you to apply series of actions in specific sequence on your class instances and it is completely independent of method implementation. Normally have two main entities. Director is responsible for defining the sequence and actions here and builders implements those actions. Can be used to represent&lt;br /&gt;
&lt;ul&gt;
&lt;li&gt;Web service response building process e.g. JSON, XML&lt;/li&gt;
&lt;/ul&gt;
&lt;pre style=&quot;background-image: URL(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh84Rur_tlUxHWvUnwN2JJsDQ-Uyy9JvqOXY_p4_cT7HKqont4q8xVdk4TOUWzDDV4e8LSyc7K6zv3S5MS6QrBwc9VuYtpq2Nk7ui_DcPWYZK5owfyirSU6IZroaF_NLQ7RuvNLwgeZ3BmD/s320/codebg.gif); background: #f0f0f0; border: 1px dashed #CCCCCC; color: black; font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;&quot;&gt;&lt;code style=&quot;color: black; word-wrap: normal;&quot;&gt; class EventDirector  
  def initialize  
   @subevents = [:welcome, :intermediary,:closing]  
  end  
  def organize event  
   @subevents.each { |se| event.send(se) if event.respond_to? se }    
  end  
 end  
 class Wedding  
  def welcome  
   p &#39;give welcome drink&#39;  
  end   
  def intermediary  
   p &#39;Exchange of vows,Exchange of rings&#39;  
  end   
  def closing  
   p &#39;closing prayer&#39;  
  end  
 end  
 class TeamParty  
  def welcome  
   p &#39;give complementry mocktail or beer :)&#39;  
  end  
  def intermediary  
   p &#39;Team building activities&#39;  
  end  
  def closing  
   p &#39;team photo&#39;  
  end   
 end  
 ed = EventDirector.new  
 ed.organize(TeamParty.new)  
 # Output =&amp;gt; &quot;give complementry mocktail or beer :)&quot;  
 # &quot;Team building activities&quot;  
 # &quot;team photo&quot;  
 ed.organize(Wedding.new)  
 # Output =&amp;gt; &quot;give welcome drink&quot;  
 # &quot;Exchange of vows,Exchange of rings&quot;  
 # &quot;closing prayer&quot;  
&lt;/code&gt;&lt;/pre&gt;</content><link rel='replies' type='application/atom+xml' href='http://rorandme.blogspot.com/feeds/1148400951812314951/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://rorandme.blogspot.com/2012/02/some-simple-design-patterns-in-ruby.html#comment-form' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8243723482882736139/posts/default/1148400951812314951'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8243723482882736139/posts/default/1148400951812314951'/><link rel='alternate' type='text/html' href='http://rorandme.blogspot.com/2012/02/some-simple-design-patterns-in-ruby.html' title='Some simple design patterns in Ruby with examples'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>2</thr:total><georss:featurename>Pune, Maharashtra, India</georss:featurename><georss:point>18.5204303 73.8567437</georss:point><georss:box>18.3999798 73.6988152 18.6408808 74.014672199999993</georss:box></entry><entry><id>tag:blogger.com,1999:blog-8243723482882736139.post-6472431294223764725</id><published>2012-02-25T02:08:00.000+05:30</published><updated>2012-02-25T02:16:28.553+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="clone"/><category scheme="http://www.blogger.com/atom/ns#" term="dup"/><category scheme="http://www.blogger.com/atom/ns#" term="object"/><category scheme="http://www.blogger.com/atom/ns#" term="Ruby"/><category scheme="http://www.blogger.com/atom/ns#" term="taint"/><category scheme="http://www.blogger.com/atom/ns#" term="tainted"/><category scheme="http://www.blogger.com/atom/ns#" term="tap"/><title type='text'>Little known methods from Object class in Ruby</title><content type='html'>&lt;b&gt;object#tap&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
Sometimes we want to insert debugging code in the middle of an statement or expression. For e.g. If you want to print the intermediate output of the following expression in order to see whether sorting works fine or not then how will you do ?&lt;br /&gt;
&lt;br /&gt;
Expression: [1,3,2,5].sort.map {|x| x * 2}&lt;br /&gt;
&lt;br /&gt;
One way is to use temporary variable... like&lt;br /&gt;
&lt;br /&gt;
sorted_arr = [1,3,2,5].sort&lt;br /&gt;
p sorted_arr&lt;br /&gt;
sorted_arr.map {|x| x * 2}&lt;br /&gt;
&lt;br /&gt;
But using tap you can simply do it like&lt;br /&gt;
&lt;br /&gt;
[1,3,2,5].sort&lt;span style=&quot;color: blue;&quot;&gt;.tap {|sa| p sa}&lt;/span&gt;.map {|x| x * 2}&lt;br /&gt;
&lt;br /&gt;
tap method doesn&#39;t disturb method chaining and still allows you to debug intermediate values.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Object#clone and Object#dup&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
Both dup &amp;amp; clone are used to create shallow copy of an object. CLONE is used to duplicate an object, including its internal state, DUP typically uses the class of the descendent object to create the new instance.&lt;br /&gt;
&lt;br /&gt;
1. clone copies both FROZEN and TAINTED state of an object along with instance variables, where as dup only copies TAINTED state of an object.&lt;br /&gt;
2. With clone you can copy any singleton methods of an object but DUP does not support this.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Object#taint&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
Consider a case where in you are writing a program in Ruby which takes input from user and evaluates it using &quot;Object#eval&quot; method. If some user gives &quot;system(&#39;rm *&#39;) as input then think of the consequences. How&amp;nbsp;insecure&amp;nbsp;it is to allow this type of data to be processed.&lt;br /&gt;
&lt;br /&gt;
To prevent this, there should be some mechanism to tell your ruby program that the data is insecure and should only be processed after some check. The concept of &quot;taint&quot; is exactly used to achieve this thing.&lt;br /&gt;
&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;br /&gt;
home = ENV[&quot;Path&quot;]&lt;br /&gt;
p home.tainted? # Output =&amp;gt; true&lt;br /&gt;
home =~ /([a-z])/&lt;br /&gt;
p $1.tainted? # Output =&amp;gt; true&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Object#public_send&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;br /&gt;
&quot;send&quot; method in Ruby can be used to call public, private and protected methods in Ruby. But what if your class have &quot;send&quot; method defined and you want to call that. How will you avoid the conflict between the &quot;send&quot; in the Object class and &quot;send&quot; in your class. Simplest solution is to use &quot;public_send&quot; method.&lt;br /&gt;
&lt;br /&gt;
class A&lt;br /&gt;
&amp;nbsp; def send&lt;br /&gt;
&amp;nbsp; &amp;nbsp; p &#39;my send&#39;&lt;br /&gt;
&amp;nbsp; end&lt;br /&gt;
end&lt;br /&gt;
A.new.public_send(:send) # Output =&amp;gt; &quot;my send&quot;&lt;br /&gt;
A.new.send(:send) # Error =&amp;gt;&amp;nbsp;in `send&#39;: wrong number of arguments (1 for 0) (ArgumentError)</content><link rel='replies' type='application/atom+xml' href='http://rorandme.blogspot.com/feeds/6472431294223764725/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://rorandme.blogspot.com/2012/02/objecttap-sometimes-we-want-to-insert.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8243723482882736139/posts/default/6472431294223764725'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8243723482882736139/posts/default/6472431294223764725'/><link rel='alternate' type='text/html' href='http://rorandme.blogspot.com/2012/02/objecttap-sometimes-we-want-to-insert.html' title='Little known methods from Object class in Ruby'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total><georss:featurename>Pune, Maharashtra, India</georss:featurename><georss:point>18.5204303 73.8567437</georss:point><georss:box>18.3999798 73.6988152 18.6408808 74.014672199999993</georss:box></entry><entry><id>tag:blogger.com,1999:blog-8243723482882736139.post-4443616650401348105</id><published>2012-02-24T00:27:00.000+05:30</published><updated>2012-02-24T00:28:10.165+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="class"/><category scheme="http://www.blogger.com/atom/ns#" term="class_eval"/><category scheme="http://www.blogger.com/atom/ns#" term="instance_eval"/><category scheme="http://www.blogger.com/atom/ns#" term="meta programming"/><category scheme="http://www.blogger.com/atom/ns#" term="module"/><category scheme="http://www.blogger.com/atom/ns#" term="Ruby"/><title type='text'>class_eval and instance_eval in Ruby Meta programming</title><content type='html'>&lt;br /&gt;
I did some experiment with meta programming keywords &quot;class_eval&quot; and &quot;instance_eval&#39;. Sharing some of the examples with you all -&lt;br /&gt;
&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;1. class_eval opens the existing class and adds the methods as defined in an ordinary class, hence they work as instance methods of that class&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
String.class_eval do&lt;br /&gt;
&amp;nbsp; def quack&lt;br /&gt;
&amp;nbsp; &amp;nbsp; p &#39;quack method&#39;&lt;br /&gt;
&amp;nbsp; end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
&quot;any string&quot;.quack&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;2.&amp;nbsp;A method defined for class A using class_eval will work as instance method of A&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
class A&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
A.class_eval do&lt;br /&gt;
&amp;nbsp; def some_method&lt;br /&gt;
&amp;nbsp; &amp;nbsp; p &#39;some_method&#39;&lt;br /&gt;
&amp;nbsp; end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
A.new.some_method&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;3.&amp;nbsp;instance_eval on a class will open the class as an instance of class Class.&amp;nbsp;Any method defined will be treated as the method of this instance which is the class.&amp;nbsp;Hence the methods work like class methods&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
class A&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
A.instance_eval do&lt;br /&gt;
&amp;nbsp; def other_method&lt;br /&gt;
&amp;nbsp; &amp;nbsp; p &#39;other_method&#39;&lt;br /&gt;
&amp;nbsp; end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
A.other_method&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;4. instance_eval on an instance of a class will open that instance of the class.&amp;nbsp;Thus it works like a singleton method that is specific to the instance and wont work for other instances of the class&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
class A&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
a = A.new&lt;br /&gt;
a.instance_eval do&lt;br /&gt;
&amp;nbsp; def a_method&lt;br /&gt;
&amp;nbsp; &amp;nbsp; p &#39;a_method&#39;&lt;br /&gt;
&amp;nbsp; end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
a.a_method &amp;nbsp;# works for &#39;a&#39; on which the instance_eval is defined&lt;br /&gt;
b = A.new&lt;br /&gt;
b.a_method &amp;nbsp;# doesn&#39;t work for &#39;b&#39;&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;5. This is the same as calling instance_eval on the instance &#39;a&#39; of class A.&amp;nbsp;This again will define a singleton method on the instance&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
class &amp;lt;&amp;lt; a&lt;br /&gt;
&amp;nbsp; def show&lt;br /&gt;
&amp;nbsp; &amp;nbsp; p &#39;this is a method&#39;&lt;br /&gt;
&amp;nbsp; end&lt;br /&gt;
end&lt;br /&gt;
a &amp;nbsp;= A.new&lt;br /&gt;
a.show&lt;br /&gt;
b.show &amp;nbsp;# doesn&#39;t work for &#39;b&#39;&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;6. &amp;nbsp;Can not call &#39;class_eval&#39; on an instance. class_eval can only be called on classes (which are instances of class Class)&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
class A&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
a.class_eval do&lt;br /&gt;
&amp;nbsp; def show_other&lt;br /&gt;
&amp;nbsp; &amp;nbsp; p &#39;this is another method&#39;&lt;br /&gt;
&amp;nbsp; end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
a = A.new
&lt;br /&gt;
a.show&lt;br /&gt;
b.show&lt;br /&gt;
&lt;br /&gt;
&lt;i&gt;Error: &amp;nbsp;in `&amp;lt;main&amp;gt;&#39;: undefined method `class_eval&#39; for #&amp;lt;A:0x455340&amp;gt; (NoMethodError)&lt;/i&gt;</content><link rel='replies' type='application/atom+xml' href='http://rorandme.blogspot.com/feeds/4443616650401348105/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://rorandme.blogspot.com/2012/02/classeval-and-instanceeval-in-meta.html#comment-form' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8243723482882736139/posts/default/4443616650401348105'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8243723482882736139/posts/default/4443616650401348105'/><link rel='alternate' type='text/html' href='http://rorandme.blogspot.com/2012/02/classeval-and-instanceeval-in-meta.html' title='class_eval and instance_eval in Ruby Meta programming'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>2</thr:total><georss:featurename>Pune, Maharashtra, India</georss:featurename><georss:point>18.5204303 73.8567437</georss:point><georss:box>18.3999798 73.6988152 18.6408808 74.014672199999993</georss:box></entry><entry><id>tag:blogger.com,1999:blog-8243723482882736139.post-5559005991447314146</id><published>2012-02-23T00:53:00.000+05:30</published><updated>2012-02-24T14:17:16.716+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="base"/><category scheme="http://www.blogger.com/atom/ns#" term="derived"/><category scheme="http://www.blogger.com/atom/ns#" term="explicit"/><category scheme="http://www.blogger.com/atom/ns#" term="implicit"/><category scheme="http://www.blogger.com/atom/ns#" term="inheritance"/><category scheme="http://www.blogger.com/atom/ns#" term="method"/><category scheme="http://www.blogger.com/atom/ns#" term="private"/><category scheme="http://www.blogger.com/atom/ns#" term="protected"/><category scheme="http://www.blogger.com/atom/ns#" term="public"/><category scheme="http://www.blogger.com/atom/ns#" term="receiver"/><category scheme="http://www.blogger.com/atom/ns#" term="Ruby"/><category scheme="http://www.blogger.com/atom/ns#" term="scope"/><title type='text'>Method scope in Ruby</title><content type='html'>&lt;link href=&quot;Page_files/filelist.xml&quot; rel=&quot;File-List&quot;&gt;&lt;/link&gt;
&lt;style id=&quot;New Microsoft Excel Worksheet_15059_Styles&quot;&gt;
&lt;!--table
 {mso-displayed-decimal-separator:&quot;\.&quot;;
 mso-displayed-thousand-separator:&quot;\,&quot;;}
.xl1515059
 {padding-top:1px;
 padding-right:1px;
 padding-left:1px;
 mso-ignore:padding;
 color:black;
 font-size:9.0pt;
 font-weight:200;
 font-style:normal;
 text-decoration:none;
 font-family:Calibri, sans-serif;
 mso-font-charset:0;
 mso-number-format:General;
 text-align:general;
 vertical-align:bottom;
 mso-background-source:auto;
 mso-pattern:auto;
 white-space:nowrap;}
.xl6515059
 {padding-top:1px;
 padding-right:1px;
 padding-left:1px;
 mso-ignore:padding;
 color:black;
 font-size:9.0pt;
 font-weight:400;
 font-style:normal;
 text-decoration:none;
 font-family:Calibri, sans-serif;
 mso-font-charset:0;
 mso-number-format:General;
 text-align:general;
 vertical-align:middle;
 mso-background-source:auto;
 mso-pattern:auto;
 white-space:nowrap;}
.xl6615059
 {padding-top:1px;
 padding-right:1px;
 padding-left:1px;
 mso-ignore:padding;
 color:black;
 font-size:9.0pt;
 font-weight:400;
 font-style:normal;
 text-decoration:none;
 font-family:Calibri, sans-serif;
 mso-font-charset:0;
 mso-number-format:General;
 text-align:center;
 vertical-align:middle;
 mso-background-source:auto;
 mso-pattern:auto;
 white-space:nowrap;}
.xl6715059
 {padding-top:1px;
 padding-right:1px;
 padding-left:1px;
 mso-ignore:padding;
 color:black;
 font-size:11.0pt;
 font-weight:700;
 font-style:normal;
 text-decoration:none;
 font-family:Calibri, sans-serif;
 mso-font-charset:0;
 mso-number-format:General;
 text-align:center;
 vertical-align:middle;
 border:.5pt solid windowtext;
 background:#EBF1DE;
 mso-pattern:black none;
 white-space:nowrap;}
.xl6815059
 {padding-top:1px;
 padding-right:1px;
 padding-left:1px;
 mso-ignore:padding;
 color:black;
 font-size:11.0pt;
 font-weight:700;
 font-style:normal;
 text-decoration:none;
 font-family:Calibri, sans-serif;
 mso-font-charset:0;
 mso-number-format:General;
 text-align:center;
 vertical-align:middle;
 border:.5pt solid windowtext;
 background:#E4DFEC;
 mso-pattern:black none;
 white-space:nowrap;}
.xl6915059
 {padding-top:1px;
 padding-right:1px;
 padding-left:1px;
 mso-ignore:padding;
 color:black;
 font-size:11.0pt;
 font-weight:700;
 font-style:normal;
 text-decoration:none;
 font-family:Calibri, sans-serif;
 mso-font-charset:0;
 mso-number-format:General;
 text-align:center;
 vertical-align:middle;
 border:.5pt solid windowtext;
 background:#DAEEF3;
 mso-pattern:black none;
 white-space:nowrap;}
.xl7015059
 {padding-top:1px;
 padding-right:1px;
 padding-left:1px;
 mso-ignore:padding;
 color:windowtext;
 font-size:11.0pt;
 font-weight:700;
 font-style:normal;
 text-decoration:none;
 font-family:Calibri, sans-serif;
 mso-font-charset:0;
 mso-number-format:General;
 text-align:center;
 vertical-align:middle;
 border:.5pt solid windowtext;
 background:#C5D9F1;
 mso-pattern:black none;
 white-space:nowrap;}
.xl7115059
 {padding-top:1px;
 padding-right:1px;
 padding-left:1px;
 mso-ignore:padding;
 color:windowtext;
 font-size:11.0pt;
 font-weight:700;
 font-style:normal;
 text-decoration:none;
 font-family:Calibri, sans-serif;
 mso-font-charset:0;
 mso-number-format:General;
 text-align:left;
 vertical-align:middle;
 border:.5pt solid windowtext;
 background:#C5D9F1;
 mso-pattern:black none;
 white-space:nowrap;}
.xl7215059
 {padding-top:1px;
 padding-right:1px;
 padding-left:1px;
 mso-ignore:padding;
 color:black;
 font-size:11.0pt;
 font-weight:400;
 font-style:normal;
 text-decoration:none;
 font-family:Calibri, sans-serif;
 mso-font-charset:0;
 mso-number-format:General;
 text-align:left;
 vertical-align:middle;
 border:.5pt solid windowtext;
 background:#EBF1DE;
 mso-pattern:black none;
 white-space:normal;}
.xl7315059
 {padding-top:1px;
 padding-right:1px;
 padding-left:1px;
 mso-ignore:padding;
 color:black;
 font-size:11.0pt;
 font-weight:400;
 font-style:normal;
 text-decoration:none;
 font-family:Calibri, sans-serif;
 mso-font-charset:0;
 mso-number-format:General;
 text-align:left;
 vertical-align:middle;
 border:.5pt solid windowtext;
 background:#E4DFEC;
 mso-pattern:black none;
 white-space:normal;}
.xl7415059
 {padding-top:1px;
 padding-right:1px;
 padding-left:1px;
 mso-ignore:padding;
 color:black;
 font-size:11.0pt;
 font-weight:400;
 font-style:normal;
 text-decoration:none;
 font-family:Calibri, sans-serif;
 mso-font-charset:0;
 mso-number-format:General;
 text-align:left;
 vertical-align:middle;
 border:.5pt solid windowtext;
 background:#DAEEF3;
 mso-pattern:black none;
 white-space:normal;}
.xl7515059
 {padding-top:1px;
 padding-right:1px;
 padding-left:1px;
 mso-ignore:padding;
 color:black;
 font-size:9.0pt;
 font-weight:400;
 font-style:normal;
 text-decoration:none;
 font-family:Calibri, sans-serif;
 mso-font-charset:0;
 mso-number-format:General;
 text-align:left;
 vertical-align:middle;
 mso-background-source:auto;
 mso-pattern:auto;
 white-space:nowrap;}
.xl7615059
 {padding-top:1px;
 padding-right:1px;
 padding-left:1px;
 mso-ignore:padding;
 color:black;
 font-size:10.0pt;
 font-weight:400;
 font-style:normal;
 text-decoration:none;
 font-family:Calibri, sans-serif;
 mso-font-charset:0;
 mso-number-format:General;
 text-align:general;
 vertical-align:bottom;
 border:.5pt solid windowtext;
 background:#EBF1DE;
 mso-pattern:black none;
 white-space:normal;}
.xl7715059
 {padding-top:1px;
 padding-right:1px;
 padding-left:1px;
 mso-ignore:padding;
 color:black;
 font-size:10.0pt;
 font-weight:400;
 font-style:normal;
 text-decoration:none;
 font-family:Calibri, sans-serif;
 mso-font-charset:0;
 mso-number-format:General;
 text-align:general;
 vertical-align:bottom;
 border:.5pt solid windowtext;
 background:#E4DFEC;
 mso-pattern:black none;
 white-space:normal;}
.xl7815059
 {padding-top:1px;
 padding-right:1px;
 padding-left:1px;
 mso-ignore:padding;
 color:black;
 font-size:9.0pt;
 font-weight:400;
 font-style:normal;
 text-decoration:none;
 font-family:Calibri, sans-serif;
 mso-font-charset:0;
 mso-number-format:General;
 text-align:general;
 vertical-align:bottom;
 border:.5pt solid windowtext;
 background:#DAEEF3;
 mso-pattern:black none;
 white-space:normal;}
--&gt;
&lt;/style&gt;
Refer to the table below to understand, what will happen on calling different type of methods in different scopes.
&lt;br /&gt;
&lt;div align=&quot;center&quot; id=&quot;New Microsoft Excel Worksheet_15059&quot; x:publishsource=&quot;Excel&quot;&gt;
&lt;table border=&quot;0&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; style=&quot;margin-left:-50px;border-collapse: collapse; table-layout: fixed; width: 860px;&quot;&gt;
 &lt;colgroup&gt;&lt;col style=&quot;width: 0pt;&quot; width=&quot;64&quot;&gt;&lt;/col&gt;
 &lt;col class=&quot;xl7515059&quot; style=&quot;mso-width-alt: 6692; mso-width-source: userset; width: 115pt;&quot; width=&quot;183&quot;&gt;&lt;/col&gt;
 &lt;col style=&quot;mso-width-alt: 25929; mso-width-source: userset; width: 330pt;&quot; width=&quot;709&quot;&gt;&lt;/col&gt;
 &lt;col class=&quot;xl6615059&quot; style=&quot;mso-width-alt: 2304; mso-width-source: userset; width: 40pt;&quot; width=&quot;63&quot;&gt;&lt;/col&gt;
 &lt;col class=&quot;xl6615059&quot; style=&quot;mso-width-alt: 2669; mso-width-source: userset; width: 45pt;&quot; width=&quot;73&quot;&gt;&lt;/col&gt;
 &lt;col class=&quot;xl6615059&quot; style=&quot;mso-width-alt: 3584; mso-width-source: userset; width: 60pt;&quot; width=&quot;98&quot;&gt;&lt;/col&gt;
 &lt;/colgroup&gt;&lt;tbody&gt;
&lt;tr height=&quot;20&quot; style=&quot;height: 15.0pt;&quot;&gt;
  &lt;td class=&quot;xl1515059&quot; height=&quot;20&quot; style=&quot;height: 15.0pt; width: 48pt;&quot; width=&quot;64&quot;&gt;&lt;/td&gt;
  &lt;td class=&quot;xl7515059&quot; style=&quot;width: 137pt;&quot; width=&quot;183&quot;&gt;&lt;/td&gt;
  &lt;td class=&quot;xl1515059&quot; style=&quot;width: 532pt;&quot; width=&quot;709&quot;&gt;&lt;/td&gt;
  &lt;td class=&quot;xl6615059&quot; style=&quot;width: 47pt;&quot; width=&quot;63&quot;&gt;&lt;/td&gt;
  &lt;td class=&quot;xl6615059&quot; style=&quot;width: 55pt;&quot; width=&quot;73&quot;&gt;&lt;/td&gt;
  &lt;td class=&quot;xl6615059&quot; style=&quot;width: 74pt;&quot; width=&quot;98&quot;&gt;&lt;/td&gt;
 &lt;/tr&gt;
&lt;tr height=&quot;20&quot; style=&quot;height: 15.0pt;&quot;&gt;
  &lt;td class=&quot;xl1515059&quot; height=&quot;20&quot; style=&quot;height: 15.0pt;&quot;&gt;&lt;/td&gt;
  &lt;td class=&quot;xl7515059&quot;&gt;&lt;/td&gt;
  &lt;td class=&quot;xl1515059&quot;&gt;&lt;/td&gt;
  &lt;td class=&quot;xl6615059&quot;&gt;&lt;/td&gt;
  &lt;td class=&quot;xl6615059&quot;&gt;&lt;/td&gt;
  &lt;td class=&quot;xl6615059&quot;&gt;&lt;/td&gt;
 &lt;/tr&gt;
&lt;tr height=&quot;20&quot; style=&quot;height: 15.0pt;&quot;&gt;
  &lt;td class=&quot;xl1515059&quot; height=&quot;20&quot; style=&quot;height: 15.0pt;&quot;&gt;&lt;/td&gt;
  &lt;td class=&quot;xl7515059&quot;&gt;&lt;/td&gt;
  &lt;td class=&quot;xl1515059&quot;&gt;&lt;/td&gt;
  &lt;td class=&quot;xl6615059&quot;&gt;&lt;/td&gt;
  &lt;td class=&quot;xl6615059&quot;&gt;&lt;/td&gt;
  &lt;td class=&quot;xl6615059&quot;&gt;&lt;/td&gt;
 &lt;/tr&gt;
&lt;tr height=&quot;20&quot; style=&quot;height: 15.0pt;&quot;&gt;
  &lt;td class=&quot;xl1515059&quot; height=&quot;20&quot; style=&quot;height: 15.0pt;&quot;&gt;&lt;/td&gt;
  &lt;td class=&quot;xl7515059&quot;&gt;&lt;/td&gt;
  &lt;td class=&quot;xl1515059&quot;&gt;&lt;/td&gt;
  &lt;td class=&quot;xl6615059&quot;&gt;&lt;/td&gt;
  &lt;td class=&quot;xl6615059&quot;&gt;&lt;/td&gt;
  &lt;td class=&quot;xl6615059&quot;&gt;&lt;/td&gt;
 &lt;/tr&gt;
&lt;tr class=&quot;xl6515059&quot; height=&quot;35&quot; style=&quot;height: 26.25pt; mso-height-source: userset;&quot;&gt;
  &lt;td class=&quot;xl6515059&quot; height=&quot;35&quot; style=&quot;height: 26.25pt;&quot;&gt;&lt;/td&gt;
  &lt;td class=&quot;xl7115059&quot;&gt;Behavior&lt;/td&gt;
  &lt;td class=&quot;xl7015059&quot; style=&quot;border-left: none;&quot;&gt;Code block&lt;/td&gt;
  &lt;td class=&quot;xl7015059&quot; style=&quot;border-left: none;&quot;&gt;Public&lt;/td&gt;
  &lt;td class=&quot;xl7015059&quot; style=&quot;border-left: none;&quot;&gt;Private&lt;/td&gt;
  &lt;td class=&quot;xl7015059&quot; style=&quot;border-left: none;&quot;&gt;Protected&lt;/td&gt;
 &lt;/tr&gt;
&lt;tr height=&quot;414&quot; style=&quot;height: 310.5pt;&quot;&gt;
  &lt;td class=&quot;xl1515059&quot; height=&quot;414&quot; style=&quot;height: 310.5pt;&quot;&gt;&lt;/td&gt;
  &lt;td class=&quot;xl7215059&quot; style=&quot;border-top: none; width: 137pt;&quot; width=&quot;183&quot;&gt;Calling
  methods from outside class (using class instance)&lt;/td&gt;
  &lt;td class=&quot;xl7615059&quot; style=&quot;border-left: none; border-top: none; width: 532pt;&quot; width=&quot;709&quot;&gt;class Base&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; def public_method&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; p &#39;public method&#39;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; end&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; def private_method&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; p &#39;private method&#39;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; end&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; def protected_method&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; p &#39;protected method&#39;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; end&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; private :private_method&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; protected :protected_method
  &lt;br /&gt;
end&lt;br /&gt;
Base.new.public_method # Output =&amp;gt; &quot;public method&quot;&lt;br /&gt;
Base.new.private_method #&amp;nbsp; Output
  =&amp;gt; private method `private_method&#39; called for #&amp;lt;A:0x2855250&amp;gt;
  (NoMethodError)&lt;br /&gt;
Base.new.protected_method # Output =&amp;gt; protected method
  `protected_method&#39; called for #&amp;lt;A:0x28552c8&amp;gt; (NoMethodError)&lt;/td&gt;
  &lt;td class=&quot;xl6715059&quot; style=&quot;border-left: none; border-top: none;&quot;&gt;Y&lt;/td&gt;
  &lt;td class=&quot;xl6715059&quot; style=&quot;border-left: none; border-top: none;&quot;&gt;N&lt;/td&gt;
  &lt;td class=&quot;xl6715059&quot; style=&quot;border-left: none; border-top: none;&quot;&gt;N&lt;/td&gt;
 &lt;/tr&gt;
&lt;tr height=&quot;437&quot; style=&quot;height: 327.75pt;&quot;&gt;
  &lt;td class=&quot;xl1515059&quot; height=&quot;437&quot; style=&quot;height: 327.75pt;&quot;&gt;&lt;/td&gt;
  &lt;td class=&quot;xl7215059&quot; style=&quot;border-top: none; width: 137pt;&quot; width=&quot;183&quot;&gt;Calling
  methods from inside class through public method (without using any implicit,
  explicit,self receiver)&lt;/td&gt;
  &lt;td class=&quot;xl7615059&quot; style=&quot;border-left: none; border-top: none; width: 532pt;&quot; width=&quot;709&quot;&gt;class Base&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; def public_method&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; p &#39;public method&#39;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; end&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; def private_method&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; p &#39;private method&#39;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; end&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; def protected_method&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; p &#39;protected method&#39;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; end&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; def calling_method&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; public_method&amp;nbsp; # Output =&amp;gt; &quot;public method&quot;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; private_method # Outuput =&amp;gt;
  &quot;private method&quot;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; protected_method # Output =&amp;gt;
  &quot;protected method&quot;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; end&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; private :private_method&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; protected :protected_method
  &lt;br /&gt;
end&lt;br /&gt;
Base.new.calling_method&lt;/td&gt;
  &lt;td class=&quot;xl6715059&quot; style=&quot;border-left: none; border-top: none;&quot;&gt;Y&lt;/td&gt;
  &lt;td class=&quot;xl6715059&quot; style=&quot;border-left: none; border-top: none;&quot;&gt;Y&lt;/td&gt;
  &lt;td class=&quot;xl6715059&quot; style=&quot;border-left: none; border-top: none;&quot;&gt;Y&lt;/td&gt;
 &lt;/tr&gt;
&lt;tr height=&quot;460&quot; style=&quot;height: 345.0pt;&quot;&gt;
  &lt;td class=&quot;xl1515059&quot; height=&quot;460&quot; style=&quot;height: 345.0pt;&quot;&gt;&lt;/td&gt;
  &lt;td class=&quot;xl7215059&quot; style=&quot;border-top: none; width: 137pt;&quot; width=&quot;183&quot;&gt;Calling
  methods from within class through public method (using self)&lt;/td&gt;
  &lt;td class=&quot;xl7615059&quot; style=&quot;border-left: none; border-top: none; width: 532pt;&quot; width=&quot;709&quot;&gt;class Base&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; def public_method&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; p &#39;public method&#39;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; end&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; def private_method&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; p &#39;private method&#39;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; end&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; def protected_method&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; p &#39;protected method&#39;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; end&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; def calling_method&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; self.public_method # Output
  =&amp;gt; &quot;public method&quot;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; self.private_method # Error
  =&amp;gt; private method `private_method&#39; called for #&amp;lt;Base:0x28551f0&amp;gt;
  (NoMethodError)&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; self.protected_method # Output
  =&amp;gt; &quot;protected method&quot;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; end&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; private :private_method&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; protected :protected_method
  &lt;br /&gt;
end&lt;br /&gt;
Base.new.calling_method&amp;nbsp;&lt;/td&gt;
  &lt;td class=&quot;xl6715059&quot; style=&quot;border-left: none; border-top: none;&quot;&gt;Y&lt;/td&gt;
  &lt;td class=&quot;xl6715059&quot; style=&quot;border-left: none; border-top: none;&quot;&gt;N&lt;/td&gt;
  &lt;td class=&quot;xl6715059&quot; style=&quot;border-left: none; border-top: none;&quot;&gt;Y&lt;/td&gt;
 &lt;/tr&gt;
&lt;tr height=&quot;460&quot; style=&quot;height: 345.0pt;&quot;&gt;
  &lt;td class=&quot;xl1515059&quot; height=&quot;460&quot; style=&quot;height: 345.0pt;&quot;&gt;&lt;/td&gt;
  &lt;td class=&quot;xl7215059&quot; style=&quot;border-top: none; width: 137pt;&quot; width=&quot;183&quot;&gt;Calling
  methods from within class through public method (using instance of class)&lt;/td&gt;
  &lt;td class=&quot;xl7615059&quot; style=&quot;border-left: none; border-top: none; width: 532pt;&quot; width=&quot;709&quot;&gt;class Base&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; def public_method&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; p &#39;public method&#39;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; end&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; def private_method&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; p &#39;private method&#39;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; end&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; def protected_method&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; p &#39;protected method&#39;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; end&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; def calling_method&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Base.new.public_method # Output
  =&amp;gt; &quot;public method&quot;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Base.new.private_method # Error
  =&amp;gt; private method `private_method&#39; called for #&amp;lt;Base:0x28551f0&amp;gt;
  (NoMethodError)&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Base.new.protected_method #
  Output =&amp;gt; &quot;protected method&quot;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; end&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; private :private_method&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; protected :protected_method
  &lt;br /&gt;
end&lt;br /&gt;
Base.new.calling_method&lt;/td&gt;
  &lt;td class=&quot;xl6715059&quot; style=&quot;border-left: none; border-top: none;&quot;&gt;Y&lt;/td&gt;
  &lt;td class=&quot;xl6715059&quot; style=&quot;border-left: none; border-top: none;&quot;&gt;N&lt;/td&gt;
  &lt;td class=&quot;xl6715059&quot; style=&quot;border-left: none; border-top: none;&quot;&gt;Y&lt;/td&gt;
 &lt;/tr&gt;
&lt;tr height=&quot;546&quot; style=&quot;height: 409.5pt;&quot;&gt;
  &lt;td class=&quot;xl1515059&quot; height=&quot;546&quot; style=&quot;height: 409.5pt;&quot;&gt;&lt;/td&gt;
  &lt;td class=&quot;xl7315059&quot; style=&quot;border-top: none; width: 137pt;&quot; width=&quot;183&quot;&gt;Calling
  methods from within derived class through public method (without using any
  implicit, explicit or self receiver)&lt;/td&gt;
  &lt;td class=&quot;xl7715059&quot; style=&quot;border-left: none; border-top: none; width: 532pt;&quot; width=&quot;709&quot;&gt;class Base&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; def public_method&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; p &#39;public method&#39;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; end&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; def private_method&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; p &#39;private method&#39;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; end&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; def protected_method&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; p &#39;protected method&#39;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; end&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; def calling_method&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Base.new.public_method&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Base.new.private_method&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Base.new.protected_method&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; end&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; private :private_method&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; protected :protected_method
  &lt;br /&gt;
end&lt;br /&gt;
class Derived &amp;lt; Base&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; def calling_method&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; public_method # Output =&amp;gt;
  &quot;public method&quot;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; private_method # Outuput =&amp;gt;
  &quot;private method&quot;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; protected_method # Output =&amp;gt;
  &quot;protected method&quot;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; end&lt;br /&gt;
end&amp;nbsp; &lt;br /&gt;
Derived.new.calling_method&lt;/td&gt;
  &lt;td class=&quot;xl6815059&quot; style=&quot;border-left: none; border-top: none;&quot;&gt;Y&lt;/td&gt;
  &lt;td class=&quot;xl6815059&quot; style=&quot;border-left: none; border-top: none;&quot;&gt;Y&lt;/td&gt;
  &lt;td class=&quot;xl6815059&quot; style=&quot;border-left: none; border-top: none;&quot;&gt;Y&lt;/td&gt;
 &lt;/tr&gt;
&lt;tr height=&quot;546&quot; style=&quot;height: 409.5pt;&quot;&gt;
  &lt;td class=&quot;xl1515059&quot; height=&quot;546&quot; style=&quot;height: 409.5pt;&quot;&gt;&lt;/td&gt;
  &lt;td class=&quot;xl7315059&quot; style=&quot;border-top: none; width: 137pt;&quot; width=&quot;183&quot;&gt;Calling
  methods from within derived class through public method using an instance of
  derived class)&lt;/td&gt;
  &lt;td class=&quot;xl7715059&quot; style=&quot;border-left: none; border-top: none; min-height: 24.25pt; width: 532pt;&quot; width=&quot;709&quot;&gt;class Base&amp;nbsp;&amp;nbsp;&amp;nbsp;
  &lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; def public_method&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; p &#39;public method&#39;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; end&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; def private_method&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; p &#39;private method&#39;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; end&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; def protected_method&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; p &#39;protected method&#39;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; end&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; def calling_method&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Base.new.public_method&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Base.new.private_method&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Base.new.protected_method&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; end&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; private :private_method&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; protected :protected_method
  &lt;br /&gt;
end&lt;br /&gt;
class Derived &amp;lt; Base&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; def calling_method&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Derived.new.public_method&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
  Derived.new.private_method&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
  Derived.new.protected_method&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; end&lt;br /&gt;
end&amp;nbsp; &lt;br /&gt;
Derived.new.calling_method&lt;/td&gt;
  &lt;td class=&quot;xl6815059&quot; style=&quot;border-left: none; border-top: none;&quot;&gt;Y&lt;/td&gt;
  &lt;td class=&quot;xl6815059&quot; style=&quot;border-left: none; border-top: none;&quot;&gt;N&lt;/td&gt;
  &lt;td class=&quot;xl6815059&quot; style=&quot;border-left: none; border-top: none;&quot;&gt;Y&lt;/td&gt;
 &lt;/tr&gt;
&lt;tr height=&quot;546&quot; style=&quot;height: 409.5pt;&quot;&gt;
  &lt;td class=&quot;xl1515059&quot; height=&quot;546&quot; style=&quot;height: 409.5pt;&quot;&gt;&lt;/td&gt;
  &lt;td class=&quot;xl7415059&quot; style=&quot;border-top: none; width: 137pt;&quot; width=&quot;183&quot;&gt;Calling
  methods from within Other class through public method using an instance of
  Other class)&lt;/td&gt;
  &lt;td class=&quot;xl7815059&quot; style=&quot;border-left: none; border-top: none; min-height: 24.25pt; width: 532pt;&quot; width=&quot;709&quot;&gt;class Base&amp;nbsp;&amp;nbsp;&amp;nbsp;
  &lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; def public_method&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; p &#39;public method&#39;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; end&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; def private_method&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; p &#39;private method&#39;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; end&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; def protected_method&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; p &#39;protected method&#39;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; end&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; def calling_method&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Base.new.public_method&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Base.new.private_method&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Base.new.protected_method&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; end&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; private :private_method&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; protected :protected_method
  &lt;br /&gt;
end&lt;br /&gt;
class Other&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; def calling_method&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Base.new.public_method&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Base.new.private_method&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Base.new.protected_method&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; end&lt;br /&gt;
end&amp;nbsp; &lt;br /&gt;
Other.new.calling_method&lt;/td&gt;
  &lt;td class=&quot;xl6915059&quot; style=&quot;border-left: none; border-top: none;&quot;&gt;Y&lt;/td&gt;
  &lt;td class=&quot;xl6915059&quot; style=&quot;border-left: none; border-top: none;&quot;&gt;N&lt;/td&gt;
  &lt;td class=&quot;xl6915059&quot; style=&quot;border-left: none; border-top: none;&quot;&gt;N&lt;/td&gt;
 &lt;/tr&gt;
&lt;tr height=&quot;0&quot; style=&quot;display: none; min-height: 24.25pt;&quot;&gt;
  &lt;td style=&quot;width: 48pt;&quot; width=&quot;64&quot;&gt;&lt;/td&gt;
  &lt;td style=&quot;width: 137pt;&quot; width=&quot;183&quot;&gt;&lt;/td&gt;
  &lt;td style=&quot;width: 532pt;&quot; width=&quot;709&quot;&gt;&lt;/td&gt;
  &lt;td style=&quot;width: 47pt;&quot; width=&quot;63&quot;&gt;&lt;/td&gt;
  &lt;td style=&quot;width: 55pt;&quot; width=&quot;73&quot;&gt;&lt;/td&gt;
  &lt;td style=&quot;width: 74pt;&quot; width=&quot;98&quot;&gt;&lt;/td&gt;
 &lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://rorandme.blogspot.com/feeds/5559005991447314146/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://rorandme.blogspot.com/2012/02/method-scope-in-ruby.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8243723482882736139/posts/default/5559005991447314146'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8243723482882736139/posts/default/5559005991447314146'/><link rel='alternate' type='text/html' href='http://rorandme.blogspot.com/2012/02/method-scope-in-ruby.html' title='Method scope in Ruby'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total><georss:featurename>Pune, Maharashtra, India</georss:featurename><georss:point>18.5204303 73.8567437</georss:point><georss:box>18.3999798 73.6988152 18.6408808 74.014672199999993</georss:box></entry><entry><id>tag:blogger.com,1999:blog-8243723482882736139.post-6400592412456429577</id><published>2012-02-22T00:55:00.000+05:30</published><updated>2012-02-22T00:56:22.480+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="david"/><category scheme="http://www.blogger.com/atom/ns#" term="dhh"/><category scheme="http://www.blogger.com/atom/ns#" term="name"/><category scheme="http://www.blogger.com/atom/ns#" term="Rails"/><category scheme="http://www.blogger.com/atom/ns#" term="why"/><title type='text'>Why the name Rails</title><content type='html'>&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhSBF2pVcuIgXB28cNQsFz9rlYYTKYYaHhFwrji4aF1qi78QV4hllw9ofC5BZuASEiHn-VCkYJS0-XmvkRiciVDNYJhKN06g4Ai4pmIx2kpXH0tZ8swjPnfXF0ULafqwnDRW-ebcqelCYHG/s1600/Gmail+-+Why+the+name+Rails+-+chirag.viradiya@gmail.com.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhSBF2pVcuIgXB28cNQsFz9rlYYTKYYaHhFwrji4aF1qi78QV4hllw9ofC5BZuASEiHn-VCkYJS0-XmvkRiciVDNYJhKN06g4Ai4pmIx2kpXH0tZ8swjPnfXF0ULafqwnDRW-ebcqelCYHG/s1600/Gmail+-+Why+the+name+Rails+-+chirag.viradiya@gmail.com.png&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;</content><link rel='replies' type='application/atom+xml' href='http://rorandme.blogspot.com/feeds/6400592412456429577/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://rorandme.blogspot.com/2012/02/why-name-rails.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8243723482882736139/posts/default/6400592412456429577'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8243723482882736139/posts/default/6400592412456429577'/><link rel='alternate' type='text/html' href='http://rorandme.blogspot.com/2012/02/why-name-rails.html' title='Why the name Rails'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhSBF2pVcuIgXB28cNQsFz9rlYYTKYYaHhFwrji4aF1qi78QV4hllw9ofC5BZuASEiHn-VCkYJS0-XmvkRiciVDNYJhKN06g4Ai4pmIx2kpXH0tZ8swjPnfXF0ULafqwnDRW-ebcqelCYHG/s72-c/Gmail+-+Why+the+name+Rails+-+chirag.viradiya@gmail.com.png" height="72" width="72"/><thr:total>0</thr:total><georss:featurename>Pune, Maharashtra, India</georss:featurename><georss:point>18.5204303 73.8567437</georss:point><georss:box>18.3999798 73.6988152 18.6408808 74.014672199999993</georss:box></entry><entry><id>tag:blogger.com,1999:blog-8243723482882736139.post-6652014304771112547</id><published>2012-02-18T12:09:00.000+05:30</published><updated>2012-02-24T00:39:12.700+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="deployment"/><category scheme="http://www.blogger.com/atom/ns#" term="https"/><category scheme="http://www.blogger.com/atom/ns#" term="nginx"/><category scheme="http://www.blogger.com/atom/ns#" term="passenger"/><category scheme="http://www.blogger.com/atom/ns#" term="passenger_pass_header"/><category scheme="http://www.blogger.com/atom/ns#" term="phusion"/><category scheme="http://www.blogger.com/atom/ns#" term="Rails"/><category scheme="http://www.blogger.com/atom/ns#" term="Ruby"/><category scheme="http://www.blogger.com/atom/ns#" term="ssl"/><category scheme="http://www.blogger.com/atom/ns#" term="ssl_requirement"/><category scheme="http://www.blogger.com/atom/ns#" term="x-forwarded-proto"/><category scheme="http://www.blogger.com/atom/ns#" term="x_forwarded_proto"/><title type='text'>the page isn&#39;t redirecting properly</title><content type='html'>&lt;b&gt;Error&amp;nbsp;on: Hitting the HTTPS rails app url&amp;nbsp; in the browser:&amp;nbsp;&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;i&gt;Error Message: &quot;the page isn&#39;t redirecting properly. Firefox has detected that the server is&amp;nbsp;redirecting the request&amp;nbsp;for this address in a&amp;nbsp;way&amp;nbsp;that will&amp;nbsp;never&amp;nbsp;complete.&quot;&amp;nbsp;&lt;/i&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Server configuration (Erroneous):&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
Rails: v3.0&lt;br /&gt;
Web server - Nginx&lt;br /&gt;
Application server - Phusion passenger &lt;br /&gt;
SSL plugin - ssl_requirement&lt;br /&gt;
Nginx configuration(inside nginx.conf):&lt;br /&gt;
&lt;br /&gt;
server {&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; listen&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 80;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ...&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; passenger_enabled on;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; ... &lt;br /&gt;
}&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; server {&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; listen 443;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ...&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ssl on;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ssl_certificate /opt/nginx/conf/certificate.pem;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ssl_certificate_key /opt/nginx/conf/server.key;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; proxy_set_headers X-Forwarded-Proto, https;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; passenger_enabled on;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ...&lt;br /&gt;
&amp;nbsp;}&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Debugging steps:&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;br /&gt;
1. Checked the nginx.conf file present in my /opt/nginx/conf directory - Everything looked fine at first glance.&lt;br /&gt;
&lt;br /&gt;
2. Checked the nginx access log file in /opt/nginx/logs directory - Found that there were lot of redirects(302)&lt;br /&gt;
&lt;br /&gt;
3. Looked at rails application log - Found that the URL was being hit but ssl was required for the action mapped to the request so Rails app was&amp;nbsp;redirecting it back to Nginx for HTTPS. Plugin used:&amp;nbsp;ssl_requirement&lt;br /&gt;
&lt;br /&gt;
4.&amp;nbsp;After digging it deeper I found that problem was something like -&lt;br /&gt;
&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;Hit the URL in Browser(HTTPS) -&amp;gt; Request got mapped to Nginx server block 443 -&amp;gt; Request redirected to Rails app (but could not find request headers required to define request as HTTPS) -&amp;gt; Rails app sent the request back to Nginx (server block 443) -&amp;gt; Nginx again redirected it to Rails app (but Rails app could not find&amp;nbsp;&lt;/b&gt;
&lt;b&gt;request headers required to define request as HTTPS&lt;/b&gt;&amp;nbsp;&lt;b&gt;) -&amp;gt; Hence again redirected back to Nginx (server block 443) -&amp;gt; So On (Infinite loop)&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
5. So I thought, the problem is on Rails application side and I looked at how Rails app decides whether the request is HTTPS or not. Found that the following snippet in ssl_requirement plugin is doing it -&lt;br /&gt;
&lt;div class=&quot;line&quot; id=&quot;LC49&quot; style=&quot;background-color: transparent;&quot;&gt;
&lt;br /&gt;
&lt;span class=&quot;k&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;ensure_proper_protocol&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line&quot; id=&quot;LC50&quot; style=&quot;background-color: transparent;&quot;&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;kp&quot;&gt;true&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;ssl_allowed?&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line&quot; id=&quot;LC52&quot; style=&quot;background-color: transparent;&quot;&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;ssl_required?&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;!&lt;/span&gt;&lt;b&gt;&lt;span class=&quot;n&quot;&gt;request&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;ssl?&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;
&lt;div class=&quot;line&quot; id=&quot;LC53&quot; style=&quot;background-color: transparent;&quot;&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span class=&quot;n&quot;&gt;redirect_to&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;https://&quot;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;request&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;host&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;request&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;request_uri&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line&quot; id=&quot;LC54&quot; style=&quot;background-color: transparent;&quot;&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span class=&quot;n&quot;&gt;flash&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;keep&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line&quot; id=&quot;LC55&quot; style=&quot;background-color: transparent;&quot;&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;kp&quot;&gt;false&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line&quot; id=&quot;LC56&quot; style=&quot;background-color: transparent;&quot;&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span class=&quot;k&quot;&gt;elsif&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;request&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;ssl?&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;!&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;ssl_required?&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line&quot; id=&quot;LC57&quot; style=&quot;background-color: transparent;&quot;&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span class=&quot;n&quot;&gt;redirect_to&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;http://&quot;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;request&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;host&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;request&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;request_uri&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line&quot; id=&quot;LC58&quot; style=&quot;background-color: transparent;&quot;&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span class=&quot;n&quot;&gt;flash&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;keep&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line&quot; id=&quot;LC59&quot; style=&quot;background-color: transparent;&quot;&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;kp&quot;&gt;false&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line&quot; id=&quot;LC60&quot; style=&quot;background-color: transparent;&quot;&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span class=&quot;k&quot;&gt;end&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;line&quot; id=&quot;LC61&quot; style=&quot;background-color: transparent;&quot;&gt;
&lt;span class=&quot;k&quot;&gt;end&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span class=&quot;k&quot;&gt;6. It was &lt;b&gt;request.ssl?&lt;/b&gt; which was deciding the type of request. Source code for the same is -&amp;nbsp;&lt;/span&gt;&lt;/div&gt;
Module: ActionDispatch::Http::URL&lt;br /&gt;
&lt;div class=&quot;line&quot; id=&quot;LC61&quot; style=&quot;background-color: transparent;&quot;&gt;
&lt;pre class=&quot;code&quot;&gt;&lt;span class=&quot;kw&quot;&gt;
&lt;/span&gt;&lt;/pre&gt;
&lt;pre class=&quot;code&quot;&gt;&lt;span class=&quot;kw&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;id ssl?&quot;&gt;ssl?&lt;/span&gt;
  &lt;span class=&quot;ivar&quot;&gt;@env&lt;/span&gt;&lt;span class=&quot;lbracket&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;tstring&quot;&gt;&lt;span class=&quot;tstring_beg&quot;&gt;&#39;&lt;/span&gt;&lt;span class=&quot;tstring_content&quot;&gt;&lt;b&gt;HTTPS&lt;/b&gt;&lt;/span&gt;&lt;span class=&quot;tstring_end&quot;&gt;&#39;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;rbracket&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;op&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;tstring&quot;&gt;&lt;span class=&quot;tstring_beg&quot;&gt;&#39;&lt;/span&gt;&lt;span class=&quot;tstring_content&quot;&gt;on&lt;/span&gt;&lt;span class=&quot;tstring_end&quot;&gt;&#39;&lt;/span&gt;&lt;/span&gt; &lt;span class=&quot;op&quot;&gt;||&lt;/span&gt; &lt;span class=&quot;ivar&quot;&gt;@env&lt;/span&gt;&lt;span class=&quot;lbracket&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;tstring&quot;&gt;&lt;span class=&quot;tstring_beg&quot;&gt;&#39;&lt;/span&gt;&lt;span class=&quot;tstring_content&quot;&gt;&lt;b&gt;HTTP_X_FORWARDED_PROTO&lt;/b&gt;&lt;/span&gt;&lt;span class=&quot;tstring_end&quot;&gt;&#39;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;rbracket&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;op&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;tstring&quot;&gt;&lt;span class=&quot;tstring_beg&quot;&gt;&#39;&lt;/span&gt;&lt;span class=&quot;tstring_content&quot;&gt;https&lt;/span&gt;&lt;span class=&quot;tstring_end&quot;&gt;&#39;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;kw&quot;&gt;end&lt;/span&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;br /&gt;
7. Finally figured out that its the values of request headers &quot;HTTPS&quot; and &quot;HTTP_X_FORWARDED_PROTO&quot; are used to define request as HTTPS.&lt;br /&gt;
&lt;br /&gt;
Now the question was why Nginx was not setting this request headers properly. The fault was default headers module, I had to use Nginx Headers more module to solve it. But that was not the complete solution. Actually headers as passed along as given below&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Nginx(Set and pass the header to) -&amp;gt; Phusion Passenger(Set and pass header to) -&amp;gt; Rails app&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
Now the second thing was to force the phusion passenger to pass the request header set by Nginx to Rails app and it can be done using passenger_pass_header directive. Finally I could get the entire thing working by using following configuration - &amp;nbsp; &lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; server {&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; listen&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 80;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; root &amp;lt;path to your rails app public folder&amp;gt;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; rails_env production;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;passenger_enabled on;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; server {&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; listen 443;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; root &amp;lt;path to your rails app public folder&amp;gt;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; rails_env production_backup;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ssl on;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ssl_certificate /opt/nginx/conf/certificate.pem;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ssl_certificate_key /opt/nginx/conf/server.key;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; more_set_input_headers &#39;X-Forwarded-Proto: https&#39;;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; passenger_pass_header X-Forwarded-Proto;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; passenger_enabled on;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br /&gt;
&lt;br /&gt;
People and URLs which helped:&lt;br /&gt;
1. http://blog.assimov.net/post/4784134814/rails-on-nginx-passenger-behind-hw-ssl-load-balancer&lt;br /&gt;
2. (Ian Neuburt) http://pastie.org/3388963&lt;br /&gt;
3. http://rubydoc.info/docs/rails/3.0.0/ActionDispatch/Http/URL#ssl%3F-instance_method- &lt;br /&gt;
&lt;div class=&quot;line&quot; id=&quot;LC61&quot; style=&quot;background-color: transparent;&quot;&gt;
&lt;/div&gt;
&lt;div class=&quot;line&quot; id=&quot;LC61&quot; style=&quot;background-color: transparent;&quot;&gt;
&lt;span class=&quot;k&quot;&gt;http://www.modrails.com/documentation/Users%20guide%20Nginx.html#_passenger_pass_header_lt_header_name_gt&lt;/span&gt;&amp;nbsp;&amp;nbsp; &lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://rorandme.blogspot.com/feeds/6652014304771112547/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://rorandme.blogspot.com/2012/02/page-isnt-redirecting-properly.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8243723482882736139/posts/default/6652014304771112547'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8243723482882736139/posts/default/6652014304771112547'/><link rel='alternate' type='text/html' href='http://rorandme.blogspot.com/2012/02/page-isnt-redirecting-properly.html' title='the page isn&#39;t redirecting properly'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total><georss:featurename>National Highway 4, Kasba Peth, Pune, Maharashtra, India</georss:featurename><georss:point>18.5204303 73.8567437</georss:point><georss:box>17.5559643 72.59331619999999 19.484896300000003 75.1201712</georss:box></entry><entry><id>tag:blogger.com,1999:blog-8243723482882736139.post-2255157156685235376</id><published>2012-02-13T16:16:00.002+05:30</published><updated>2012-02-13T16:16:20.642+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="Cheat sheet"/><category scheme="http://www.blogger.com/atom/ns#" term="Rails"/><category scheme="http://www.blogger.com/atom/ns#" term="Ruby"/><title type='text'>Ruby on Rails - All cheatsheets</title><content type='html'>After certain amount of experience, it is very difficult to remember syntax while coding. And cheat sheets are to rescue you at that instance. I always find it very handy so sharing with you few cheat sheets which I find useful. I myself have verified all the links (and they are all up at the time of writing this post).&lt;br /&gt;
&lt;br /&gt;
1. A &lt;a href=&quot;http://www.addedbytes.com/cheat-sheets/ruby-on-rails-cheat-sheet/&quot; target=&quot;_blank&quot;&gt;quick reference guide&lt;/a&gt; for Ruby on Rails, containing the default 
directory structure, predefined variables, methods, reserved words and 
regular expression syntax.&lt;br /&gt;
&lt;br /&gt;
2.&amp;nbsp;&lt;a href=&quot;http://blog.envylabs.com/Rails_3_Cheat_Sheets.pdf&quot; target=&quot;_blank&quot;&gt;Rails 3 Cheat Sheets&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
3. &lt;a href=&quot;http://www.undefinedrange.com/files/active_resource.png%20&quot; target=&quot;_blank&quot;&gt;Active Resource cheat sheet&amp;nbsp;&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
4. &lt;a href=&quot;http://centricle.com/ref/css/filters/?highlight_columns=true&quot; target=&quot;_blank&quot;&gt;Browser compatibility table&lt;/a&gt;&lt;br /&gt;
 &lt;br /&gt;
 5. &lt;a href=&quot;http://topfunky.com/clients/peepcode/REST-cheatsheet.pdf&quot; target=&quot;_blank&quot;&gt;RESTful routes cheat sheet&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
6. A&lt;a href=&quot;http://snook.ca/archives/javascript/prototype_disse/&quot; target=&quot;_blank&quot;&gt;wesome Prototype cheat sheets&lt;/a&gt;. Prototype is a JavaScript library used as default with Rails. &lt;br /&gt;
&lt;br /&gt;
7. &lt;a href=&quot;http://blog.daveastels.com/files/QuickRef.pdf&quot; target=&quot;_blank&quot;&gt;Rspec cheat sheets&lt;/a&gt; by Dave Astels(one of the Rspec developer). &lt;span class=&quot;st&quot;&gt;&lt;em&gt;RSpec&lt;/em&gt; is a behavior driven development (BDD) framework for the Ruby programming language, inspired by JBehave.&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span class=&quot;st&quot;&gt;New useful cheat sheet will find way into my post as and when I come across them !!!&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;st&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;st&quot;&gt;PS: Please report in case any of the links above is not working.&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;st&quot;&gt;&lt;br /&gt;&lt;/span&gt;</content><link rel='replies' type='application/atom+xml' href='http://rorandme.blogspot.com/feeds/2255157156685235376/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://rorandme.blogspot.com/2012/02/ruby-on-rails-all-cheatsheets.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8243723482882736139/posts/default/2255157156685235376'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8243723482882736139/posts/default/2255157156685235376'/><link rel='alternate' type='text/html' href='http://rorandme.blogspot.com/2012/02/ruby-on-rails-all-cheatsheets.html' title='Ruby on Rails - All cheatsheets'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total><georss:featurename>Pune, Maharashtra, India</georss:featurename><georss:point>18.5204303 73.8567437</georss:point><georss:box>18.3999798 73.6988152 18.6408808 74.014672199999993</georss:box></entry><entry><id>tag:blogger.com,1999:blog-8243723482882736139.post-4154390466428542219</id><published>2012-02-10T11:52:00.000+05:30</published><updated>2012-02-10T12:01:16.184+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="internals"/><category scheme="http://www.blogger.com/atom/ns#" term="matz"/><category scheme="http://www.blogger.com/atom/ns#" term="Minero"/><category scheme="http://www.blogger.com/atom/ns#" term="Ruby"/><title type='text'>Learn Ruby internals and C code behind it</title><content type='html'>The best way to learn Ruby is to understand the C code behind Ruby.&lt;br /&gt;
&lt;br /&gt;
But it becomes very difficult for many people like me who are not very much proficient/hands on in C. Also, it is very difficult to find out what is important to understand and what is comparatively trivial to be skipped. &lt;br /&gt;
&lt;br /&gt;
But do not worry,&amp;nbsp; there exists an awesome &lt;a href=&quot;https://docs.google.com/open?id=0B23Ol-aDuoc_MzNmMDhiZjItZTA2NS00OTQ5LWE0NDctNTU5ODM4YzM2NDAx&quot;&gt;Ruby Hacking Guide&lt;/a&gt; on the web, which is so awesome. If you really want to look into Ruby internals please have a look at it. If you feel that it looks little bit old then you can check &lt;a href=&quot;http://www.hawthorne-press.com/&quot;&gt;this website&lt;/a&gt;.&lt;br /&gt;
&lt;br /&gt;
Thanks Matz for creating Ruby and Minero AOKI for such a nice guide.&lt;br /&gt;
&lt;br /&gt;</content><link rel='replies' type='application/atom+xml' href='http://rorandme.blogspot.com/feeds/4154390466428542219/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://rorandme.blogspot.com/2012/02/learn-ruby-internals-and-c-code-behind.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8243723482882736139/posts/default/4154390466428542219'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8243723482882736139/posts/default/4154390466428542219'/><link rel='alternate' type='text/html' href='http://rorandme.blogspot.com/2012/02/learn-ruby-internals-and-c-code-behind.html' title='Learn Ruby internals and C code behind it'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total><georss:featurename>Pune, Maharashtra, India</georss:featurename><georss:point>18.5204303 73.8567437</georss:point><georss:box>18.3999798 73.6988152 18.6408808 74.014672199999993</georss:box></entry><entry><id>tag:blogger.com,1999:blog-8243723482882736139.post-8191438780529126147</id><published>2012-02-10T11:26:00.003+05:30</published><updated>2013-07-07T16:52:36.446+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="application"/><category scheme="http://www.blogger.com/atom/ns#" term="rack"/><category scheme="http://www.blogger.com/atom/ns#" term="Ruby"/><category scheme="http://www.blogger.com/atom/ns#" term="Web"/><title type='text'>A web application written in plain Ruby </title><content type='html'>require &#39;rubygems&#39;&lt;br /&gt;
require &#39;rack&#39;&lt;br /&gt;
&lt;br /&gt;
class WebApp&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; def call(env)&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; [200, {&quot;content-type&quot; =&amp;gt;&quot;text/html&quot;}, &quot;hello World&quot;]&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; end&lt;br /&gt;
end&lt;br /&gt;
&amp;nbsp; &lt;br /&gt;
Rack::Handler::Mongrel.run(WebApp.new, :port =&amp;gt; 3000)</content><link rel='replies' type='application/atom+xml' href='http://rorandme.blogspot.com/feeds/8191438780529126147/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://rorandme.blogspot.com/2012/02/small-ruby-web-application.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8243723482882736139/posts/default/8191438780529126147'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8243723482882736139/posts/default/8191438780529126147'/><link rel='alternate' type='text/html' href='http://rorandme.blogspot.com/2012/02/small-ruby-web-application.html' title='A web application written in plain Ruby '/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total><georss:featurename>Pune, Maharashtra, India</georss:featurename><georss:point>18.5204303 73.8567437</georss:point><georss:box>18.3999798 73.6988152 18.6408808 74.014672199999993</georss:box></entry><entry><id>tag:blogger.com,1999:blog-8243723482882736139.post-4033768142278901439</id><published>2012-02-08T20:10:00.000+05:30</published><updated>2012-02-24T00:51:58.627+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="Convert"/><category scheme="http://www.blogger.com/atom/ns#" term="recursion"/><category scheme="http://www.blogger.com/atom/ns#" term="Roman"/><category scheme="http://www.blogger.com/atom/ns#" term="Ruby"/><title type='text'>One possible Ruby way to convert Integer to Roman</title><content type='html'>&lt;br /&gt;
class Roman&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; def initialize&lt;br /&gt;
&amp;nbsp; &amp;nbsp; @romans = { 1 =&amp;gt; &#39;I&#39;,5 =&amp;gt; &#39;V&#39;,10 =&amp;gt; &#39;X&#39;,50 =&amp;gt; &#39;L&#39;,100 =&amp;gt; &#39;C&#39;,500 =&amp;gt; &#39;D&#39;,1000 =&amp;gt; &#39;M&#39; }&lt;br /&gt;
&amp;nbsp; end&lt;br /&gt;
&amp;nbsp;&lt;br /&gt;
&amp;nbsp; def romanize(num, outnum=&quot;&quot;)&lt;br /&gt;
&amp;nbsp; &amp;nbsp; digits = num.to_s.length &lt;br /&gt;
&amp;nbsp; &amp;nbsp; range_up = 10**digits&lt;br /&gt;
&amp;nbsp; &amp;nbsp; unit = range_low = range_up/10&lt;br /&gt;
&amp;nbsp; &amp;nbsp; range_mid = range_up/2 &amp;nbsp; &lt;br /&gt;
&amp;nbsp; &amp;nbsp; numerator = (num/unit) * unit&lt;br /&gt;
&amp;nbsp; &amp;nbsp; nextnum = num%unit &lt;br /&gt;
&amp;nbsp; &amp;nbsp; if(@romans.has_key?(numerator))&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; outnum += @romans[numerator]&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; romanize(nextnum, outnum) &amp;nbsp; &amp;nbsp; &lt;br /&gt;
&amp;nbsp; &amp;nbsp; elsif (numerator == range_up - unit)&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; outnum += @romans[unit] + @romans[range_up] &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; elsif(numerator == range_mid - unit)&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; outnum += @romans[unit] + @romans[range_mid]&lt;br /&gt;
&amp;nbsp; &amp;nbsp; elsif(numerator &amp;gt; range_mid)&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; outnum += @romans[range_mid]&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; romanize(num - range_mid, outnum)&lt;br /&gt;
&amp;nbsp; &amp;nbsp; else&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; outnum += @romans[range_low] * (numerator/range_low) &amp;nbsp; &amp;nbsp;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; end &lt;br /&gt;
&amp;nbsp; &amp;nbsp; num == 0 ? (return num,outnum) : romanize(nextnum, outnum)&lt;br /&gt;
&amp;nbsp; end&lt;br /&gt;
&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
n, o = Roman.new.romanize(101)&lt;br /&gt;
p &quot;101:#{o}&quot; # =&amp;gt; &quot;101:CI&quot;&lt;br /&gt;
&lt;br /&gt;
n, o = Roman.new.romanize(999)&lt;br /&gt;
p &quot;999:#{o}&quot; # =&amp;gt; &quot;999:CMXCIX&quot;&lt;br /&gt;
&lt;br /&gt;
n, o = Roman.new.romanize(505)&lt;br /&gt;
p &quot;505:#{o}&quot; =&amp;gt; &quot;505:DV&quot;&lt;br /&gt;</content><link rel='replies' type='application/atom+xml' href='http://rorandme.blogspot.com/feeds/4033768142278901439/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://rorandme.blogspot.com/2012/02/one-possible-ruby-way-to-convert.html#comment-form' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8243723482882736139/posts/default/4033768142278901439'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8243723482882736139/posts/default/4033768142278901439'/><link rel='alternate' type='text/html' href='http://rorandme.blogspot.com/2012/02/one-possible-ruby-way-to-convert.html' title='One possible Ruby way to convert Integer to Roman'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total><georss:featurename>Pune, Maharashtra, India</georss:featurename><georss:point>18.5204303 73.8567437</georss:point><georss:box>18.3999798 73.6988152 18.6408808 74.014672199999993</georss:box></entry><entry><id>tag:blogger.com,1999:blog-8243723482882736139.post-4781899617670767716</id><published>2012-02-07T18:43:00.000+05:30</published><updated>2012-02-24T00:48:15.485+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="ruby discrepancies OOP ruby1.8.7 errors"/><title type='text'>These things about Ruby1.8.7, I really don&#39;t understand</title><content type='html'>&lt;br /&gt;
&lt;b&gt;1. Why Ruby allows to use instance variable as class variable ?&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
class A &lt;br /&gt;
&amp;nbsp; @v_one = 1 &lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; def self.get_v_one&lt;br /&gt;
&amp;nbsp; &amp;nbsp; @v_one&lt;br /&gt;
&amp;nbsp; end&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; def why_this&lt;br /&gt;
&amp;nbsp; &amp;nbsp; p @v_one&lt;br /&gt;
&amp;nbsp; &amp;nbsp; p self.class.get_v_one &amp;nbsp; &amp;nbsp;# @v_one behaves as class variable here&lt;br /&gt;
&amp;nbsp; end &lt;br /&gt;
end&lt;br /&gt;
A.new.why_this&lt;br /&gt;
&lt;br /&gt;
# Output&lt;br /&gt;
&amp;gt;ruby test.rb&lt;br /&gt;
nil&lt;br /&gt;
1&lt;br /&gt;
&lt;br /&gt;
&lt;i&gt;Questions:&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;1. If I can use the &quot;@&quot; as class variable as shown above why Ruby has &quot;@@&quot;. Just for convenience or is there anything else to it?&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;2. Why Ruby allows to put instance variable into class, how does it makes sense?&lt;/i&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;2. Why Ruby allows to call private methods from derived class ?&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
class Base&lt;br /&gt;
&amp;nbsp; def why_this&lt;br /&gt;
&amp;nbsp; &amp;nbsp; p &#39;Called from derived class, it should not have.&#39;&lt;br /&gt;
&amp;nbsp; end&lt;br /&gt;
&amp;nbsp; private :why_this&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
class Derived &amp;lt; Base&lt;br /&gt;
&amp;nbsp; def call_me&lt;br /&gt;
&amp;nbsp; &amp;nbsp; why_this&lt;br /&gt;
&amp;nbsp; end &lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
Derived.new.call_me&lt;br /&gt;
&lt;br /&gt;
# Output&lt;br /&gt;
&amp;gt;ruby test.rb&lt;br /&gt;
&quot;Called from derived class, it should not have.&quot;&lt;br /&gt;
&amp;gt;Exit code: 0&lt;br /&gt;
&lt;br /&gt;
&lt;i&gt;Question:&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;1. Aren&#39;t private methods are specific to class only ? How come they are accessed in derived class?&lt;/i&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;3. Why Ruby gives Derived class variable value even if I use the Base class instance ?&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
class Base &amp;nbsp; &lt;br /&gt;
&amp;nbsp; &amp;nbsp; @@v_one = 1&lt;br /&gt;
&amp;nbsp; &amp;nbsp; def why_this&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; p @@v_one&lt;br /&gt;
&amp;nbsp; &amp;nbsp; end &amp;nbsp; &lt;br /&gt;
end&lt;br /&gt;
class Derived &amp;lt; Base&lt;br /&gt;
&amp;nbsp; &amp;nbsp; @@v_one = 2 &amp;nbsp; &lt;br /&gt;
end &amp;nbsp;&lt;br /&gt;
Base.new.why_this&lt;br /&gt;
&lt;br /&gt;
# Output&lt;br /&gt;
&amp;gt;ruby test.rb&lt;br /&gt;
2&lt;br /&gt;
&amp;gt;Exit code: 0&lt;br /&gt;
&lt;br /&gt;
&lt;i&gt;Questions: &amp;nbsp;&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;1. Can this cause any security risks? Anybody can subclass the Base class and redefine the value of class variables in Base&lt;/i&gt;.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;4. Isn&#39;t the calling of private methods little bit inconsistent ?&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
class A &lt;br /&gt;
&amp;nbsp; &amp;nbsp; def why_this&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; p &#39;private method&#39;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; end &lt;br /&gt;
&amp;nbsp; &amp;nbsp; private :why_this&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
A.new.send(:why_this) &amp;nbsp;# Output =&amp;gt; &quot;private method&quot;&lt;br /&gt;
A.new.why_this # Out=&amp;gt; private method `why_this&#39; called for #&amp;lt;A:0x2855688&amp;gt; (NoMethodError)&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;5. Why array subtraction is confusing ?&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
a = [1,2,2,3]&lt;br /&gt;
b = [2]&lt;br /&gt;
p a - b &amp;nbsp;#=&amp;gt; [1,3]&lt;br /&gt;
# Ideally the result should have been [1,2,3]&lt;br /&gt;
&lt;br /&gt;
&lt;i&gt;Questions:&amp;nbsp;&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;1. Why is it removing both members with value &quot;2&quot; ?&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;2. Does it internally use Set to perform subtraction?&lt;/i&gt;&lt;br /&gt;
&lt;br /&gt;</content><link rel='replies' type='application/atom+xml' href='http://rorandme.blogspot.com/feeds/4781899617670767716/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://rorandme.blogspot.com/2012/02/these-things-about-ruby187-i-really.html#comment-form' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8243723482882736139/posts/default/4781899617670767716'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8243723482882736139/posts/default/4781899617670767716'/><link rel='alternate' type='text/html' href='http://rorandme.blogspot.com/2012/02/these-things-about-ruby187-i-really.html' title='These things about Ruby1.8.7, I really don&#39;t understand'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>2</thr:total><georss:featurename>Pune, Maharashtra, India</georss:featurename><georss:point>18.5204303 73.8567437</georss:point><georss:box>18.3999798 73.6988152 18.6408808 74.014672199999993</georss:box></entry></feed>