Monday, March 22, 2010

city_select plugin to display list of indian city in dropdown list

city_select - city_select is the plugin which is basically used for to display the list of indian cities as a drop down list.

The implementation is simple

.script/plugin install

I have implemented it using jquery.

$("#user_state").change(function() {var id=('#user_state').attr("value"); $.ajax({url: "update_city/"+id, dataType: "script", type: 'get' })});

. "#user_state" is the dropdown list which contain the list of state name(I have consider the value of user_state as a FULL STATE NAME(for e.g. "Maharashtra") instead of STATE CODE).

Make a render file let say _city_select.erb and inside the controller render the _city_select.erb file and parse the selected state

Feel free to add a city if I am missing one.


Thursday, October 8, 2009

Ruby, class and some random stuff - Module, inheritance, MLI

module NowModule

class NowModuleOne

class << self
def find
p "This is intresting!!!"


class Parent < NowModule::NowModuleOne
def parentone
puts "This is the parent class!!!"

class << self
def parentself
puts "This is the self one!!!"

def parentprotected
puts "This is the protect one!!!"


def parentprivate
puts "This is the private one!!!"


#example of inheritance....
class Child < Parent
def childone
p parentone
puts "This is the child class!!!"

#example of multiple level inheritance
class ChildOfChild < Child
def childofchildone
#the parentone belongs to the parent class which a base class for the Child class..

p =
c =
cc =

Monday, September 28, 2009

Connect to database using ruby and ActiveRecord

To get connected you database from your ruby file just include the "ActiveRecord" inside your ruby file.

require 'rubygems'
require 'activerecord'

#establish the connection.
:adapter => "mysql",
:database => "database",
:username => "username",
:password => "password",
:host => "localhost"

#create a class inherit with you activerecord base class.
class User < ActiveRecord::Base

user = User.find(:first)
puts user

class SomeThing < ActiveRecord::Base
set_table_name :users

user = SomeThing.find(:first)
puts user

That's It.

Ruby Mysql database connectivity

In this section I am going to tell you how do you get connected your MySQL database using Ruby.

Make sure that you have install mysql adapter
To verify you mysql file go to command prompt type irb -> require 'mysql' if it's return true that means the file is loaded.

Now use your fav editor let say scite.

require 'rubygems'
require 'mysql'

#establish a connection.
mysql = Mysql.real_connect("hostname(e.g - localhost)", "username", "password", "databasename")
result = mysql.query("SELECT * FROM USERS;")
result.each do |row|
row.each do |col|
puts col
#the col object will return the value from the users table.
# if you want to insert a record. then
mysql.query("INSERT INTO users (email) VALUES ('')")
#this is how you can edit delete the records...
rescue Exception => e
puts "I guess something went wrong. #{e}"
# clone the connection...
mysql.close if mysql

Friday, September 11, 2009

bash: cap: command not found

bash: cap: command not found

In this post I'll be talking about how to resolve the “bash: cap: command not found” issue. Even after installing Capistrano we get the following error “bash: cap: command not found” the reason behind this is that the path is not decalred in bash file, so to fix the problem you have to add the following line on code inside bashrc file

Step 1
#go to Terminal
sudo gedit ~/.bashrc

Step 2
#Add the following line at the bottom of the file.
export PATH=$PATH:/home/user/.gem/ruby/1.8
#save and close
# To find the installation of you gem just run the following command
#gem list -d c
# capistrano (2.5.8)
# Authors: Jamis Buck, Lee Hambley
# Rubyforge:
# Homepage:
# Installed at: /home/user/.gem/ruby/1.8

Step 3
#From command prompt
source ~/.bashrc

Wednesday, September 9, 2009

File Upload using AJAX and jQuery.

File Upload using AJAX and jQuery.

File upload using jQuery is preety simple.

NOTE: please include the jQuery Library afer prototype.js

As you can in the above example I had declared “jQuery.noConflict();” the reason behind this is to abvoid the conflict between jQuery library and prototype.js.

<% remote_form_for :some_random_name, @some_object, :url => {:action => 'testtest'},
:html => { :multipart => true, :id => "upload_form" } do |f| %>

<%= file_field_tag "test" "uploaded" %>
< id="button" class="button" value="Add File" type="button">
< id="save" class="save" value="Upload" type="submit">

Thats it.

Monday, May 25, 2009

How to integrate Comatose CMS in your rails application.

Comatose CMS Yet another Micro CMS, when your client may use to create and edit easily a static pages like privacy policy, terms & conditions, an FAQ, that kind of thing.

Installation of Camotose.
$ ./script/plugin install git://
$ ./script/generate comatose_migration
$ rake db:migrate

Once the above mentioned command is executed then configure your route file, at the bottom of your route file paste the below mention syntax
map.comatose_root ''

That it now you to access the Camotose simply type

You can configure you comatose on your config/environment.rb file, but i'll suggest you to create a comatose.rb inside your config/initializers folder, and insert the following code.

Comatose.configure do |config|
config.admin_title = 'YOUR site name CMS SYSTEM' # it cab anything...
config.admin_helpers = []
config.admin_sub_title = 'Administration Pages'
config.content_type = 'utf-8'
config.default_filter = ''
#config.default_processor = :liquid
config.default_tree_level = 3
config.disable_caching = false
config.hidden_meta_fields = 'filter'
config.helpers = []
config.includes = []
# These are 'blockable' settings
config.authorization = { true }
config.admin_get_author = { request.env['REMOTE_ADDR'] }
config.after_setup = { true }

# Includes AuthenticationSystem in the ComatoseAdminController
config.admin_includes << :authenticated_system

# Calls :login_required as a before_filter
config.admin_authorization = :login_required