Archive for the ‘ruby’ Category

Sort array of ActiveRecord object without querying to database.

Sometimes it may happen you want to sort the array of objects, fetched from ActiveRecord.
e.g. I have a users table having name column after I done any manipulation on the fetched object.
You can just call the following code for doing the above stuff.

@users = User.find :all
@users = @users – xyz_obj.users #remove existing users.
@users = @users.sort_by [...]

How to raise and rescue Exceptions in Ruby on Rails

Creating the Exception class
To create our “PersonalException” we just need to extend “Exception” class.

class PersonalException < Exception
end

Raise our Exception

raise PersonalException.new, “message”

Rescue our exception
We can do this by overwriting rescue_action_in_public and local_request? functions to our application.rb file:

Ruby thumbnail generator

Ruby thumbnail generator is simple script which is ideal to use in your Ruby on Rails application to quickly generate thumbnails of any proportions. Just set width and height and get the image.
1. copy following code into /controllers/thumb_controller.rb
2. edit /config/routes.rb and add this line:map.connect “thumb/*specs”, :controller => “thumb”, :action => “index”
3. create directory /imagelib/ in [...]

god Server process monitoring and notifying tool written in ruby

Progress on god is moving along as quick as ever. Most interestingly you’ll find several useful new command line functions:

god status prints out the status of each Watch
god log shows realtime logs for a specific Watch (even if you don’t have god logging to file)
god load loads or reloads a config file into a running [...]

Ruby On Rails Security Guide

Ruby on Rails does a decent job in handling security concerns in the background. You will have to configure your application to avoid few security attacks while plugins would be required for many security concerns which are not at all or poorly managed by rails.

Authentication
Authentication is the foremost requirement of most of the web applications [...]

Reading An Excel File With Ruby

This tutorial will cover how to read (or parse) an excel file with ruby. Here’s how you can do the same thing.
Installing Parseexcel
Parseexcel is a ruby port of the perl parseexcel module.
It’s installable via a nice gem like so:
 
 
gem install parseexcel
That’s that, now remember since it’s a gem library we have to tell our [...]