Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 

Default function for Increment/Decrement updates database field values in rails 2.3.8

Generally at the time of development a situation of incrementing or decrementing a database field it can come like Number of views for a particular page or Number of views of a individual profile. In rails there are two default functions for this...

How to Apply Active Record Observer on a Particular Column

Meaning:- Active Record Observers means a callback or a trigger which will get called in the life cycle of active record object. This is used for the purpose of reducing the burden on model's functionality which is not directly belongs to model....

Install pdfkit and wkhtmltopdf library on Ubuntu 12.04/ruby

This library is used to create pdf from html. Steps to install: #Install wkhtmltopdf library in ruby by using below command: apt-get install wkhtmltopdf #Use below command to find the path. This path need to add in in pdfkit.rb[in i...

how to get remaining months between two dates in ruby

Below is the code to get remaining months between two dates date1 = '2011-03-31' date2 = '2011-02-25' (date1.to_date.year * 12 + date1.to_date.month) - (date2.to_date.year * 12 + date2.to_date.month) ...

How to create Ruby hash in just one line ?

When we have to create a hash in just one line we can use this particular ruby code: @users = User.find :all user_hash = Hash[@users.map {|x| [x.id, x.name]}] Here we created a hash in just one line with Id as the key of hash a...

Ruby Sort an array of objects in hash with case insensitive attribute

To sort an array of objects in hash @users = User.find(:all) @users.sort_by(&:employee_name) Above code will sort @users object with all employee name with Capital letter first and then small letter. ...

Removing file using Spreadsheet in windows( Errno::EACCESS(Permission denied))

There is no close method in spreadsheet.If you opened the spreadsheet and after reading you need to delete it then FIleUtils.rm(file_name) will work smoothly in linux but in windows it will give permission error Errno::EACCESS(Permission den...

How to keep the order in ruby hashes

When we insert the data into a ruby hash it reorders the data in some other order when we use it in view file.So there are cases when we have to show the data in the same order in the order we are inserting the data into ruby hash.So in case wher...

Format floating number

"%g" % (float_number) Above function formats float number to natural number if it contains zero's after decimal point otherwise format float upto one decimal point Helpful in showing working days(like 22.5 days)

Upload image in ruby on rails through AJAX

Upload image in ruby on rails through AJAX This is HTML and JavaScript code. <% remote_form_for(:image_upload_form, :url => "/meeting/save_image/", :html => { :method => :post, :id => 'imgForm', :multipart => true }) do |f...
1 4 6 next
Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: