<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Code &#38; Config - sharing the smart bits &#187; Rails</title>
	<atom:link href="http://code.lewro.com/category/rails/feed/" rel="self" type="application/rss+xml" />
	<link>http://code.lewro.com</link>
	<description>Code &#38; Config - sharing the smart bits</description>
	<lastBuildDate>Sun, 22 Jan 2012 13:30:37 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Installing RVM which allows you to run multiple Ruby environments on one machine</title>
		<link>http://code.lewro.com/rails/installing-rvm-which-allows-you-to-run-multiple-ruby-environments-on-one-machine/</link>
		<comments>http://code.lewro.com/rails/installing-rvm-which-allows-you-to-run-multiple-ruby-environments-on-one-machine/#comments</comments>
		<pubDate>Sun, 22 Jan 2012 13:26:13 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Rails]]></category>

		<guid isPermaLink="false">http://code.lewro.com/?p=240</guid>
		<description><![CDATA[Install from the source bash -s stable &#60; &#60;(curl -s https://raw.github.com/wayneeseguin/rvm/master/binscripts/rvm-installer ) Reload the bash profile source .bash_profile Check if the RVM is installed. Is should return &#8220;rvm is a function&#8221;. Note: It&#8217;s gonna take while type rvm &#124; head -1 Install ruby 1.9.2. (for example) rvm install 1.9.2 Use the ruby you just installed [...]]]></description>
			<content:encoded><![CDATA[<p>Install from the source</p>
<pre class="brush: ruby;">
  bash -s stable &lt; &lt;(curl -s https://raw.github.com/wayneeseguin/rvm/master/binscripts/rvm-installer )
</pre>
<p>Reload the bash profile</p>
<pre class="brush: ruby;">
  source .bash_profile
</pre>
<p>Check if the RVM is installed. Is should return &#8220;rvm is a function&#8221;.<br />
Note: It&#8217;s gonna take while</p>
<pre class="brush: ruby;">
  type rvm | head -1
</pre>
<p>Install ruby 1.9.2. (for example)</p>
<pre class="brush: ruby;">
  rvm install 1.9.2
</pre>
<p>Use the ruby you just installed<br />
[command]<br />
  rvm use 1.9.2<br />
[/command]</p>
]]></content:encoded>
			<wfw:commentRss>http://code.lewro.com/rails/installing-rvm-which-allows-you-to-run-multiple-ruby-environments-on-one-machine/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Implement Cron into your Rails application</title>
		<link>http://code.lewro.com/rails/implement-cron-into-your-rails-application/</link>
		<comments>http://code.lewro.com/rails/implement-cron-into-your-rails-application/#comments</comments>
		<pubDate>Tue, 11 Jan 2011 13:23:37 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Rails]]></category>

		<guid isPermaLink="false">http://code.lewro.com/?p=216</guid>
		<description><![CDATA[There is a much better solution available for implementing Cron Jobs in Rails application then editing the crontab file on your server. Editing the file by hand requires knowing the cron syntax and what is worst that you need to update the cron file on every server where your application is running. Here is better [...]]]></description>
			<content:encoded><![CDATA[<p>There is a much better solution available for implementing Cron Jobs in Rails application then editing the crontab file on your server.<br />
Editing the file by hand requires knowing the cron syntax and what is worst that you need to update the cron file on every server where your application is running. </p>
<p>Here is better solution.<br />
Install gem called &#8211; Whenever.</p>
<pre class="brush: ruby;">
gem install whenever

#Wheneverize your application, which will create an schedule file - config/schedule.rb&quot;
wheneverize .

#Set your cron jobs in the schedule file using ruby syntax
#The syntax is pretty self explanatory 

every :reboot do
  command &quot;sudo mount /dev/sdf /mnt/data&quot;
  command &quot;sudo /etc/init.d/mysql start&quot;
end

every 1.day,  :at =&gt; &quot;1am&quot; do
  runner &quot;Task.deadline_emails&quot;
end

#After every change run this command to update the system cron
# whenever --update-crontab same_name_to_identify_the_job

#Update your deploy file (when using Capistrano)
after 'deploy', 'update_crontab'
task :update_crontab, :roles =&gt; :db do
  run &quot;cd #{release_path} &amp;&amp; whenever --update-crontab #{application}&quot;
end
</pre>
]]></content:encoded>
			<wfw:commentRss>http://code.lewro.com/rails/implement-cron-into-your-rails-application/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Prevent user from accessing  the app. after logout with back button (rails only)</title>
		<link>http://code.lewro.com/rails/prevent-user-from-accessing-the-app-after-logout-with-back-button-rails-only/</link>
		<comments>http://code.lewro.com/rails/prevent-user-from-accessing-the-app-after-logout-with-back-button-rails-only/#comments</comments>
		<pubDate>Sun, 26 Dec 2010 22:28:08 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Rails]]></category>

		<guid isPermaLink="false">http://code.lewro.com/?p=208</guid>
		<description><![CDATA[Inserting this code into application controller. setting the headers into the past should solve the problem as well as turning the cashe off. def set_cache_buster response.headers[&#34;Cache-Control&#34;] = &#34;no-cache, no-store, max-age=0, must-revalidate&#34; response.headers[&#34;Pragma&#34;] = &#34;no-cache&#34; response.headers[&#34;Expires&#34;] = &#34;Fri, 01 Jan 1990 00:00:00 GMT&#34; end Inserts this code into every controller (where it make sense) before_filter :set_cache_buster]]></description>
			<content:encoded><![CDATA[<p>Inserting this code into application controller.<br />
setting the headers into the past should solve the problem as well as turning the cashe off. </p>
<pre class="brush: ruby;">
  def set_cache_buster
    response.headers[&quot;Cache-Control&quot;] = &quot;no-cache, no-store, max-age=0, must-revalidate&quot;
    response.headers[&quot;Pragma&quot;] = &quot;no-cache&quot;
    response.headers[&quot;Expires&quot;] = &quot;Fri, 01 Jan 1990 00:00:00 GMT&quot;
  end
</pre>
<p>Inserts this code into every controller (where it make sense)</p>
<pre class="brush: ruby;">
  before_filter :set_cache_buster
</pre>
]]></content:encoded>
			<wfw:commentRss>http://code.lewro.com/rails/prevent-user-from-accessing-the-app-after-logout-with-back-button-rails-only/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Rollback migration in Ruby on Rails</title>
		<link>http://code.lewro.com/rails/rollback-migration-in-ruby-on-rails/</link>
		<comments>http://code.lewro.com/rails/rollback-migration-in-ruby-on-rails/#comments</comments>
		<pubDate>Mon, 04 Oct 2010 11:37:05 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Rails]]></category>

		<guid isPermaLink="false">http://code.lewro.com/?p=200</guid>
		<description><![CDATA[I am someone who often forgets things or makes mistake. If you make mistake in the migrations inside your ROR project there is a easy and intuitive way how to put things back into the stage they have been before so you can fix stuff and then migrate the dtb again with the correct values. [...]]]></description>
			<content:encoded><![CDATA[<p>I am someone who often forgets things or makes mistake. If you make mistake in the migrations inside your ROR project there is a easy and intuitive way how to put things back into the stage they have been before so you can fix stuff and then migrate the dtb again with the correct values. </p>
<p>Here is how you can cancel the latest migration. It basically executes the self.down part of your migration so do not forget to specify it when you creating your new migrations. </p>
<pre class="brush: ruby;">
rake db:rollback
</pre>
]]></content:encoded>
			<wfw:commentRss>http://code.lewro.com/rails/rollback-migration-in-ruby-on-rails/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to setup deployment the right way using Capistrano.</title>
		<link>http://code.lewro.com/rails/how-to-setup-deployment-the-right-way-using-capistrano/</link>
		<comments>http://code.lewro.com/rails/how-to-setup-deployment-the-right-way-using-capistrano/#comments</comments>
		<pubDate>Mon, 26 Apr 2010 19:31:44 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Rails]]></category>

		<guid isPermaLink="false">http://code.lewro.com/?p=169</guid>
		<description><![CDATA[First of all lets define the environment I am using. I am using Amazon EC2 server which is running Ubuntu and I am going to use Capistrano to deploy my Rails application. I am also using GitHub as my code repository. Let me describe in a humanly understandable way what will actually be happening. You [...]]]></description>
			<content:encoded><![CDATA[<p>First of all lets define the environment I am using. I am using Amazon EC2 server which is running Ubuntu and I am going to use Capistrano to deploy my Rails application. I am also using GitHub as my code repository. </p>
<p>Let me describe in a humanly understandable way what will actually be happening. You will call the deployment by syntax such as “cap production deploy” and the whole clever magic will happen at the background. What magic? So here it comes. Capistrano will use your SSH key to connect to your EC2 instance, from there it will connect to your GitHub account and will pull the latest version of your code into a specific folder. Capistrano will afterwards simlink the running application with the latest version which has just been pulled from Git and woalla you have the app. deployed. </p>
<p>Before you can start deploying with Capistrano there are couple of things you need to do. You will need SSH key which use use to connect to your EC2. I actually think that Capistrano requires both the public and private keys to be stored on your computer. You will also need to generate SSH key while connected to you EC2 instance. You will need to store the public version of this key in your GitHub account details. These keys will allows us to connect to EC2 instance and GitHub. That is all we need for safe connections. </p>
<p>I have said that in this example I am running Ubuntu server on my EC2 instance. To generate and store the SSH key on the Ubuntu server you might need to run the commands over ssh agent. You will get there by executing the following command. </p>
<pre class="brush: bash;">
ssh-agent bash
</pre>
<p>Now you should be able to generated and “add” the SSH key. If you are not sure how, <a href="http://code.lewro.com/git/create-ssh-key-for-git-or-any-other-purposes/">check my article about generating SSH keys</a>. </p>
<p>The folder you need to use for you SSH key sits in here &#8211; /home/ubuntu/.ssh as you are connected as user: ubuntu</p>
<p>One important note. I have found out that you can’t specify your own name for SSH key and you need to leave the password blank (just hit enter). The key will get the default name. </p>
<p>After you copied the public version of the key to your GitHub account you can double check by using the following command. </p>
<pre class="brush: bash;">
ssh git@github.com
</pre>
<p>You should be invited with your name and you will also get an security note. Just ignore that for now. </p>
<h4>Installing Capistrano</h4>
<p>The capistrano gem can be installed from <a href="http://www.capify.org/index.php/Capistrano">here</a>. </p>
<p>After the gem is installed you will need to capify your application. Get into the root of your application and execute this command. </p>
<pre class="brush: bash;">
	capify .
</pre>
<p>This will create the necessary files and folders. You will find a file called deployment inside of your config directory. </p>
<p>These is the configuration you will need to add in. </p>
<pre class="brush: bash;">

set :application, &quot;the_name_of_your_application&quot;
set :repository,  &quot;git@github.com:your_git_hub_name/the_name_of_your_application.git&quot;
set :scm, :git

set :user, &quot;ubuntu&quot;
set :use_sudo, false

#environment = 'production'

ssh_options[:keys] = [&quot;#{ENV['HOME']}/.ssh/ec2key.pem&quot;]  // This is the path to your EC2 ssh key 

// Deploying to Production 

task :production do
  role :web, &quot;YOUR_EC2_ADDRESS.compute-1.amazonaws.com&quot;
  role :app, &quot;YOUR_EC2_ADDRESS.compute-1.amazonaws.com&quot;
  role :db,  &quot;YOUR_EC2_ADDRESS.compute-1.amazonaws.com&quot;, :primary =&gt; true

  set :deploy_to, &quot;/mnt/data/quantify/production/&quot; // The folder where you will store your application on EC2. You will need to create these directories on your server before deployment. Note that my application sits in /mnt/data directory which is an Amazon elastic block. Do not deploy your app. in different directory otherwise you might loose all data if the instance experiences problems

  set :rails_env, :production
  set :current_path, &quot;#{deploy_to}current&quot;

  environment = 'production'
end

// I am also running test server on the same machine
// The same task is used to deploy to test/staging environment. There are only two differences. The folder name where the app. will be deployed to and the name of the environment. 

task :staging do
  role :web, &quot;YOUR_EC2_ADDRESS.compute-1.amazonaws.com&quot;
  role :app, &quot;YOUR_EC2_ADDRESS.compute-1.amazonaws.com&quot;
  role :db,  &quot;YOUR_EC2_ADDRESS.compute-1.amazonaws.com&quot;, :primary =&gt; true

  set :deploy_to, &quot;/mnt/data/quantify/test/&quot;
  set :rails_env, :test
  set :current_path, &quot;#{deploy_to}current&quot;

  environment = 'test'
end

//  This code will set permissions and restart the application after deployment

after 'deploy', 'set_permissions'
after 'deploy:setup', 'set_permissions'

task :set_permissions do
  sudo &quot;chown ubuntu #{deploy_to}&quot;
  sudo &quot;chmod -R g+w #{deploy_to}&quot;
end

namespace :deploy do
  task :restart do
    run &quot;#{try_sudo} touch #{File.join(current_path,'tmp','restart.txt')}&quot;
  end
end
</pre>
<p>If you are wondering how to setup test server or name servers for your domain name I will describe it in the next article so stay tuned.</p>
]]></content:encoded>
			<wfw:commentRss>http://code.lewro.com/rails/how-to-setup-deployment-the-right-way-using-capistrano/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Setting up top part of your controllers in Rails</title>
		<link>http://code.lewro.com/rails/setting-up-top-part-of-your-controllers-in-rails/</link>
		<comments>http://code.lewro.com/rails/setting-up-top-part-of-your-controllers-in-rails/#comments</comments>
		<pubDate>Sun, 21 Feb 2010 20:02:47 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Rails]]></category>

		<guid isPermaLink="false">http://code.lewro.com/?p=141</guid>
		<description><![CDATA[Ruby on Rails is MVC environment. The C part of MVC goes for Controller. This is the place where you define your actions. The are couple of standard actions, such are Index, Show, Update, Destroy, but you can obviously create any other one you need. There are two handy parameters you might want to setup [...]]]></description>
			<content:encoded><![CDATA[<p>Ruby on Rails is MVC environment. The C part of MVC goes for Controller. This is the place where you define your actions. The are couple of standard actions, such are Index, Show, Update, Destroy, but you can obviously create any other one you need. There are two handy parameters you might want to setup before you specify your actions. The first one is layout type and the second one is before_filter. </p>
<p>The project controller would start like this.</p>
<pre class="brush: ruby;">
class ProjectsController &lt; ApplicationController

 #you can have different versions of layout so here you specify which one you want this controller to use when it is rendered
 #there is layouts directory in the views directory, you would find the standard.htm.erb file sitting in there
  layout 'standard'

 #here you can setup if the page can be accessed for strangers (users who are not logged in)
 #as you can see in my case it is not possible
  before_filter :login_required

  # this is how you would define action in rails
  def index
  end

end
</pre>
]]></content:encoded>
			<wfw:commentRss>http://code.lewro.com/rails/setting-up-top-part-of-your-controllers-in-rails/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

