Archive for the ‘about this site’ Category

11 Things to Consider Before Deploying Your Rails Application

Monday, November 16th, 2009

At VinSol, we have been developing and deploying Rails applications for more than four years. During this period, we  have identified some best practices that we prefer to follow while deploying  rails application to production server.

Below is the checklist of these practices:

 

1. Ensure that NS records and MX records are changed if they need to be changed

Changing nameservers will point the domain to the hosting server,  and changing MX records will redirect incoming mails to the mail server. As a very first step, we should make sure that name servers of the domain are set to be the correct one.  Changing MX record is a must if our application is parsing incoming mails or we wants to use other mail services for e-mail exchange, for example Gmail.

 

2. Ensure some backup mechanism in place for both data as well as user uploaded content like images/documents etc.

Since production data is very critical, we must setup backup  mechanism. It could be some type of scheduled task that takes periodic backup of all critical data, Or it could be some type of backup service provided by hosting company. When we talk about critical production data, it includes production DB, content generated by application users like images, documents, etc.

 

3. Ensure database indexes

We might have done development without having proper database indexes, but we should avoid going to production without them. Adding indexes might slow down insert queries a bit but it increases the  performance of read queries. It applies when application in production has percentage of read operations much more than write operations.

 

4. Enable your slow query log

This is specific to MySQL. Enabling slow query log allows MySQL to log slow running queries to a file. And this log can be used to find queries that take a long time to execute and are therefore candidates for optimization.

 

5. Ensure exception capturing is in place

We might want to be notified when something bad happens to our application. There are several hosted services available who receive and track exceptions, for example Hoptoadapp.com, GetExceptional.com etc…  Either we can choose one from these hosted services or we can use “exception notifier” plugin.

 

6. Ensure adding entries for cron/scheduled jobs

Most of the applications have some functionality/jobs that need to be run periodically, for example generating invoices, sending newsletters etc.  In most cases these jobs are done by a rake task. We should make sure that we have added such jobs to cron or similar program.

 

7.  Monitoring important processes

To ensure that our site is up 24×7 we need to ensure that all processes that our application needs are up. There can be many processes like MySQL, Mongrel, Apache etc.. These processes are very important as our application directly depends on them. For example if MySQL process get killed accidentally, our application would not be able to connect to MySQL and will start throwing exceptions.

We can choose any of the available monitoring tools like God, Monit, 24×7 etc…

 

8. Ensure confidential data filtering

We would never like to leak/share confidential information of our application users. We should make sure that none of the user’s confidential data like SSN, Credit card info, password are being written to log files. We might not have paid much attention on this while developing the application.

 

9. Rotate log files

Once our site is up and running, every single request write some text in log file. And hence size of the  log file keeps on increasing. Larger log files can put us in trouble if we get it beyond certain size. Its difficult to manage these log files, as larger files need more memory to open and need more time to download. In one of the rescue project we did , the log file size was 3GB.

We would recommend having logrotate setup for the application.

 

10. Setup Asset Host

Setting up asset hosts can reduce loading time by 50% or more. We must setup asset hosts for our application. Once asset hosts are all set, our static files will be delivered via asset hosts for example asset1.hostname.com, asset2.hostname.com

 

11. Clearing up stale sessions

We should make sure we should not left any stale session on the server. If our application is using DB or file system  as session store, we must add a schedule task to delete stale sessions.

These are some of the points we have identified from our past experience and we might be missing some. Feel free to  always add them as comments, and I’ll keep this post updated.


Akhil is a senior software engineer working with Vinsol for last 5 years. He is an inhouse deployment ninja.

 

 

We also provide affordable rails deployment services.

 

 

10 little known ways to find a ruby on rails team for your next project

Thursday, November 12th, 2009

Everytime we talk to our clients, we find that they are not aware of lot of options through which they can find a good rails developer. Usually clients go to odesk and other freelance websites to find rails developers. Following are  10 more ways to find  rails company/developer for your next dream project :

  1. Post your requirements on twitter with hashtag #ruby #ror #rails
  2. Go to Railsdevelopment.com - its a directory of rails companies. You can search for specific services with your budget ranges.
  3. Working with Rails – Again a directory of rails developers and companies. You can browse through specific industry categories.
  4. Local Ruby Meetups – The most passionate guys are always there in local meetups. For eg: we have delhi ruby meetups and you can find all local meetups in australia here
  5. RubyJobs – Post a job on rubyjobs or rubyinside job board. There are some country specific ruby job boards.
  6. RubyonRails wiki – There is a wiki of ruby on rails companies.
  7. Open Source Contributions – Sites like http://agilewebdevelopment.com/ gives you a directory of rails plugins. Open Source contributions such as releasing a Rails plugin, or fixing bugs on projects , or Rails itself, demonstrates exposure to other Rails code bases and quality of a developer. Search for developer name in github.
  8. Conferences – Conferences are good way to find quality rails developer or team.
  9. Facebook – Few people post jobs on facebook.

Few tips :

  • Don’t hire someone that doesn’t know Rails at all. Yes, we have seen some people doing it.
  • Ask for references of previous clients if possible in your country.
  • Look for someone who values the money you are paying them and will make your investment in them provide a valuable return.
  • A personal Rails blog is a good indicator of  developer’s interests , experience and resume.

How to Integrate TinyMce with Redbox in 5 steps ?

Friday, September 4th, 2009

TinyMCE is a platform independent web based Javascript HTML WYSIWYG editor control. It has the ability to convert HTML TEXTAREA fields or other HTML elements to editor instances.

Redbox is a library that pops a modal box over a web page, using CSS and javascript, so that you can ask the user a question, or show them something important. The box can be loaded from content already on the page (but hidden), or it can be loaded via AJAX. The contents of the box can be replaced using AJAX, for multi-page forms, and it can be closed easily using a javascript link.

Here is the process for integrating Redbox and tinymce.

Step I:
Install required plugins:

- TinyMce(http://github.com/kete/tiny_mce/tree/master)
- RedBox(http://www.craigambrose.com/projects/redbox)

Step II:
Include javascript files to layout:

  <%= include_tiny_mce_js %>
  <%= javascript_tag "initialize_editor();" %>

Now, add this javascript method which initilizes the text editor. You can specify the options you want for your text editor here.

Javascript:

function  initialize_editor(){
  tinyMCE.init({
    theme:"advanced",
    //mode:"textareas", // this is commented because we do not want to apply the editor to all the text area
     instances. Instead, we will use the class "mceEditor" to specify on which element we want to add the editor.
    theme_advanced_toolbar_location:"top",
    theme_advanced_toolbar_align:"left",
    theme_advanced_resizing:true,
    theme_advanced_resize_horizontal:false,
    paste_auto_cleanup_on_paste:true,
theme_advanced_blockformats:"p,address,pre,h1,h2,h3,h4,h5,h6",
    theme_advanced_buttons1:"bold, italic, underline, strikethrough, | , undo, redo, link, unlink, image, | , bullist, numlist",
    theme_advanced_buttons2:"",
    theme_advanced_buttons3:"",
    dialog_type:"modal"
  });
}


Step III:


Add editor class “mceEditor” to the text area where you want the editor to be added.

<%= f.text_area :details, :id => 'ta_id', :class => 'mceEditor' %>

Now, we need to create a tinymce editor control for the text area(’ta_id’) on loading the popup so add this “execCommand” loads the tinyMCE in the textarea.

<script type="text\javascript">
  tinyMCE.execCommand('mceAddControl', true, "ta_id");
</script>

Step IV:


When we submit our form and copy over the editor content to the text box it references. Tinymce provides a method ‘triggerSave’ that moves the contents from the editor to the form field. This method is automatically called by tinyMCE by adding a trigger on the forms submit method.

Save the content:

<%= f.submit 'Save', :class => 'primaryAction', :onclick => "tinyMCE.triggerSave(true,true);" %>

Step V:


Whenever we close our popup redbox we need to remove the tinymce editor control that we had added. Remove control on closing the redbox:

<%= link_to_close_redbox 'Close', {:onclick => "tinyMCE.execCommand('mceRemoveControl', true, 'ta_id'});"} %>

Works on: Firefox(1.5+), Safari and IE(7+)

For Internet Explorer we need to initialize the editor on loading the pop-up but for firefox we need to initalize editor on loading the main page. So we need modify our javascript

<script type="text\javascript">
  if(navigator.appName=="Microsoft Internet Explorer")
  	initialize_editor();
  tinyMCE.execCommand('mceAddControl', true, "ta_id");
</script>

And so here we are ready to go in just five simple steps.

Refer here for more details.

Now You Can Have Better Youtube Integration with Ruby on Rails

Thursday, July 30th, 2009

I recently wanted to upload, edit, update and delete a video directly on youtube from my rails application. This can be achieved by YouTube Data API that allows application to perform functions normally executed on youtube.

Step 1 : Demystifying Authentication with Google AuthSub

Google provides an authentication service to those web applications that need to access services protected by a user’s Google account. I chose Google’s ‘AuthSub’ scheme for this. This also provides a high level of security to web application.
The AuthSub interface provides several methods for acquiring and managing authorization tokens. Once a web application has received a token, it can request access to a Google service.

To obtain an authentication token, submit an HTTP POST request to the following URL:

https://www.google.com/accounts/AuthSubRequest?next=http%3A%2F%2Fwww.example.com%2Fupload.html&scope=http%3A%2F%2Fgdata.youtube.com&session=0&secure=0

Setting session parameter to 1 indicates that the single-use token can be exchanged for a session token.
AuthSubSessionToken is a method that allows the web application to exchange a single-use token for a session token. I used a gem ‘gdata’ to convert the token into a session token.

client = GData::Client::DocList.new
client.authsub_token = params[:token]
session[:token] = client.auth_handler.upgrade()

Session token allows the application to make unlimited calls to the Google service. When using session tokens, your application should store the session token for each user rather than requesting a new one each time it needs to access a Google service. For other token management options, see Working With AuthSub.

Step 2 : Getting the Youtube Developer Key

A developer key is required that identifies the YouTube developer that is submitting an API request. A client ID identifies your application for logging and debugging purposes. Please visit here to obtain a developer key and client ID.

Step 3 : Improving the Youtube Model Plugin

“youtube-model” is a plugin  that provides youtube video uploading functionality. That was a good start.
I forked the plugin and updated it with few methods to get the rest of  the functionality done. Each method is explained here.
1. uploaded_by_user
A method uploaded_by was provided in the plugin to retrieve all the videos of the user but it receives username as a parameter. So I added a method uploaded_by_user that receives the session token and solves our purpose.

YouTube.uploaded_by_user(session[:token])

2. update_video
The video can be updated by using this method passing video id, session token and params hash as parameters.

YouTube.update_video(params[:id], session[:token], params[:you_tube_entry])

3. delete_video
The video can also be deleted if uploaded at the user’s youtube account by passing video id and token as a parameter.

YouTube.delete_video(params[:id], session[:token])

4. video_status
This method helps finding out the status of uploaded video.

s = YouTube.video_status(session[:token], params[:id])
@status = s.control.state.name

The changes to the plugin have been merged in the master and you can download everything here. I will really appreciate your feedback and suggestions to make this plugin better.

Vibha Chadha is working with Vinsol as a rails developer. When she is not writing code, she likes to read “geek” books and listen  to some “good” music.

RailsConf Day 1 – Links to slides and blog posts

Tuesday, May 5th, 2009
  • This is the official link for all the presentation files, so whenever you are looking for PPTs , this is the first place

http://en.oreilly.com/rails2009/public/schedule/proceedings

Please add any other userful links which I missed through comments. Looking forward for day 2. We are wearing black t -shirts with Vinsol printed in red.