Veerasundaravel's Ruby on Rails Weblog

September 22, 2010

Bundler: Best way to manage your Gems

Bundler Gem

As the name itself will specify the purpose of it. Bundler gem is used to bundle all of your required ruby gems.

The bundler allows the specification of all dependencies in a separate place from the application itself. You can specify the required version of gems and its entire set of dependencies.
So while deploying your application in a server no need to install the gem from Rubyforge or etc.

Steps to follow:

1. At the root of your application, run gem install bundler

2. Create a Gemfile in the root of your application

3. Add dependencies to your Gemfile. like gem “rspec”, 1.2.3

4. At the root, run bundle install. It will install all the gems which you specified in Gemfile from the remote system. And it will create a file called Gemfile.lock. The purpose of Gemfile.lock is to get the list of gems installed and its dependencies in your app.

5. And now run bundle package. It will make a copy of your installed gems into your application path vendor/cache. It will more helpful when you are deploying your app in any other server. Cos after running bundle package, your application will look gems into vendor/cache instead of remote systems.

For more details:

September 17, 2010

ActiveRecord – Tableless Model

If you want to create an ActiveRecord model without any table reference, and want to add validation for that model means, you can go with this example code.

In app/models/base_model.rb

class BaseModel < ActiveRecord::Base
def self.columns
@columns ||= [];

def self.column(name, sql_type = nil, default = nil, null = true)
columns <<, default,
sql_type.to_s, null)

# Override the save method to prevent exceptions.
def save(validate = true)
validate ? valid? : true

In app/models/post.rb

class Article < BaseModel
column :title, :string
validates_presence_of :title

In script/console

Loading development environment (Rails 2.2.2)
>> article =
=> #<Article title: nil>
>> article.valid?
=> false
>> article.errors
=> #<ActiveRecord::Errors:0x235b270 @errors={“title”=>[“can’t be blank”]}, @base=#<Article title: nil>>

Reference Links:

September 16, 2010

Styling the Browse button using jQuery

Browsers do not let you style file inputs. File Style plugin fixes this problem. It enables you to use image as browse button. You can also style filename field as normal textfield using css. It is written using JavaScript and jQuery.

Want to see how it works? Check the demo page.

Thanks to RajaSelvam for introducing this plugin.

Reference URL:

Older Posts »

%d bloggers like this: