Posts tagged with : ruby

Associate with ActiveResourceAssociatable


A communication of a web app with others is not a surprise, but it is the demand of mobile world's era. Because new apps want to maintain a centralized DB which could be shared with other apps very easily and very frequently. Recently, I also worked on a similar distributed web app which provided me an idea to implement a rubygem.

ActiveResource is a ruby library which acts same as ActiveRecord, but perform operations over API. ActiveResourceAssociatable is also a ruby library which consolidates same kind of associations methods as ActiveRecord provides. However it could be achieved by own customized methods, but ActiveResourceAssociatable provides smarter way of accessing your ActiveRecord and ActiveResource methods. ActiveResourceAssociatable comes with some options too which will make you more easy to use this gem.

ActiveResourceAssociatable

More...


Roda versus Rails


Few days back, I heard about Roda which could suppose to be a replacement of Rails. Roda is a routing tree web toolkit, designed for building fast and maintainable web applications in ruby. The creator of Roda is Jeremy Evans. Rails is dead we hear it every years and it is more widespread after twitter's jump from Rails to Scala.

According to Jeremy Evans, Roda provides Simplicity, Reliability, Extensibility and Performance. Roda has low per-request overhead, and the use of a routing tree and intelligent caching of internal datastructures makes it significantly faster than popular ruby web frameworks. But as per my opinion, Rails is good and getting more mature, stable and popularity every year. Here I will compare these two over some points.

Prerequisites

More...


Is ActiveSupport::Concern really Another Concern?


In Ruby world, Rails is a well known web-framework and ActiveSupport is an integrated component. ActiveSupport is a ruby gem which comes with rails by default. But, we can also use this library or gem separately. ActiveSupport is very easy to understand upto the extend that if you are planning to read the source code of rails, then start with ActiveSupport. So, today I am going to throw some light on ActiveSupport::Concern which is also one of the component of ActiveSupport. Is ActiveSupport::Concern really Another Concern?

This post is for those who are new to ActiveSupport. Who constantly do utility work like encoding, or decoding JSON, generating random number, number to currency conversion etc. But never got the chance to find out the reason behind this. Have you ever looked into the source code of any rubygem where you found the statement like extend ActiveSupport::Concern. If yes, are you familiar with this statement? Why do we use this? Trust me ActiveSupport::Concern is not a concern, but to make your life easy.

ActiveSupport::Concern is useful in mixin or modules. It is more useful whenever you are building your own rubygem.

Without ActiveSupport::Concern

More...


How To Wire up Ruby on Rails and Ampersand.js As a Single Page Application


Ampersand.js is a latest web framework like any other javascript framework e.g. Angularjs. By definition,

Ampersand.js - A highly modular, loosely coupled, non-frameworky framework for building advanced JavaScript apps.

This definition is correct. Ampersandjs is really a non-frameworky framework. Now question comes, Why Ampersand.js?. Because we love Backbone.js, and Ampersand.js is written on the top of Backbone.js. For more details, please refer http://ampersandjs.com.

In this article, I am explaining you to build a simple single page application (not simple as much as any hello world or todo app :)) using rails and ampersand.js. The application will be wired-up with a Rails application and will fetch all its data from rails generated APIs. In fact, behind the scene, Rails application is providing the APIs directly from the file app/assets/javascripts/ampersandtest/data.json. You can also fetch the data from any other application too using your web-service call. The source code is residing on my github repository Source Code and demo is available on Demo. Let's start from scratch.

Basic Installation

More...


Smart Deployment using Hubot


Github is an invariably well-known name in the world of open source. Githut consistently provides a propitious and favorable platforms for any betterment, reform or innovation in the technology which could also discern as an your open source contribution. Hubot is also one of such examples which posses the sovereign potential to metamorphose the process of deployment of rails apps. I came across the term hubot last year and I also heard that numerous enter-prize level organizations benefiting their processes by hubot. My curiosity enabled me up-to the extent that now I am writing a blog :).

Hubot describes its work as an amazing campfire bot who plays the vital role of an user, deployed on heroku, and will add into your campfire chat room as a normal user through heroku URL. However, the heroku app will be revealing as an error page which could cause a confusion in your mind about credibility of the chat bot.

First of all, deploy a dummy app on heroku which could be initiated using this command.

gem install heroku

I am assuming here that you are familiar some what with heroku and have created your profile and deployed some app on heroku. If not, please refer https://id.heroku.com/signup or https://devcenter.heroku.com/articles/git. Then setup the heroku app:

heroku create --stack 
git push heroku master 
heroku ps:scale web=1

Now, you will need to setup your HEROKU_URL variable.

heroku config:add HEROKU_URL=

Work in Progress ...




Successful Migration from svn to git with history


I am a git lover, not svn. But, when I started my programming, svn was so popular and widespread. But the discovery of git pushed the paradigm shift in world of version control. Git is better than svn in lot of senses which could easily be delineated with the fact that most of the open source contributions and repositories are found on Github. Github could be recognized as the UI interface for git version control.

The time has changed, but yet there are many projects are still residing on svn. This article will enable you to successfully migrate from your old svn version control to new git version control with the help of few chunck of statements. The astonishing fact is that this will not lose your history too.

Lets say your project name is dummyapp and its residing on svn say http://svn/Other/RubyOnRails/apps/dummyapp/trunk.

1). Please go to your local svn copy on your local workstation.

cd PATH_TO_LOCAL_SVN_COPY

2). Create a file say authors-transform.txt which will be having list of all users of current svn dummyapp application.

svn log -q | awk -F '|' '/^r/ {sub("^ ", "", $2); sub(" $", "", $2); print $2" = "$2" <"$2">"}' | sort -u > authors-transform.txt

This command will fetch all users who have made any commit to dummyapp svn application before, then sort them and store in authors-transform.txt file.

3). Now, install git-svn on your system.

sudo apt-get install git-svn (on linux)

I am not sure about windows, but there will be any application to perform this task in windows also (Please help yourself window users).

4). Now, execute the command

git svn clone svn://svn/Other/RubyOnRails/apps/dummyapp/trunk -A authors-transform.txt  ~/temp

This command will take relatively longer time as it fetches all history of the svn application. For every commit in SVN, it will generate corresponding git commit ID, assign the commiter name and by default create the master branch. As well as, it will copy the whole application as a git repository on your local in temp directory (as in my case the temp directory is there in my home folder)

5). Once step 4 is completed, go to temp directory (cd ~/temp). Create origin remote and assign it to github path.

git remote add origin git@github.com:dummyapp.git

6). Push the code to github.

git push origin master

Thats it !!!

Congratulation !!! Your application has been successfully moved over github with all of its histories and users etc.


Ruby-oci8 with Rails


Ruby-oci8 is a rubygem which we use to build the connection with oracle DB in your rails application. But installation of ruby-oci8 on linux or mac is not easy, while its a bit tricky. When I started to configure it on my mac first time, it consumed the entire day to google and configure. Therefore, I am trying to explain you the local configuration and installation here. However this post is only for linux and mac, but not for windows.

Hmmmmm, let's start with the basics. I am assuming that you are using rails-3.0+ and ruby-1.8.7+. As we do with Rails-3 applications, We maintain a Gemfile and in order to install gems, we run bundle install. But, if you have specified ruby-oci8 gem, then just wait for few moments. This will be failed unless you have proper configuration.

1). You will need to install and configure oracle instant client first. Please download and install oracle instant client. The directions for installation is already given, but be careful to choose correct instant client version which could differ according to your machine.

2). Next, you will need to set your environment. Set environment variable LD_LIBRARY_PATH (DYLD_LIBRARY_PATH in case of mac). Just run this command on your terminal or console.

In case of Linux

 export LD_LIBRARY_PATH="/usr/lib/oracle/11.2/client64/"

In case of Mac

 export DYLD_LIBRARY_PATH="/usr/local/oracle/instantclient_11_2"

Or, you can add this command in your .bashrc or .zshrc file too and then run the command source .bashrc or source .zshrc.

This will set the value of environment variable LD_LIBRARY_PATH as "/usr/lib/oracle/11.2/client64/".

Also, check that this location does have the client installed. If not, find out where it is and create a soft link to here. ruby-oci8 expects to find it at this location “/usr/lib/oracle/….”.

3). In this last step, you need to make a symlink. Just run this command

sudo ln -s /usr/include/linux/ /usr/include/sysclient

In last, it must work after this. If its not working, then just drop a comment here, may be I could help you more.


Visit the archives!