File column plugin not working with rails 2.2

Older version of file_coulmn plugin is not working in rails 2.2.

If you want to get working in rails 2.2 then you need to modify file_coulmn.rb file.

Update the line #619 in vendor/plugins/file_column/lib/file_column.rb from

Inflector.underscore(self.name).to_s,
to
ActiveSupport::Inflector.underscore(self.name).to_s,

Or you can download the latest plugin from the github.com: http://github.com/rust/file_column/

If you are looking to implement the old File column plugin you may visit

http://blog.dhavalparikh.co.in/2008/02/file-column-plugin/

Be Sociable, Share!

Google Charts in Rails (gc4r)

Well I m going to cover the topic how to generate charts using rails. there are number of options available such as follows

Here are the plugins through which we can generate charts in rails

1) Gruff charts http://nubyonrails.com/articles/gruff-graphing-library-for-ruby

2) Sparklines http://nubyonrails.com/articles/sparklines-graph-library-for-ruby

3) Scruffy charts http://scruffy.rubyforge.org/

4) Ziya plugin http://liquidrail.com/2007/1/4/charting-the-rails/ (flash charts)

I found google charts the best of these..( ofcourse that suited my requirements). The gc4r plugin in rails is really helpful for easy integration of google charts in your rails application.

Here is how Charts are generated by Google API.

Install: ruby script/plugin install http://gc4r.googlecode.com/svn/trunk/

Supported features:
1.line chart
2.bar chart (vertical and horizontal)
3.pie chart (both 2D and 3D)
4.title, title color and size
5.data colors and legend
6.data scaling
7.multiple axis

#Controller
use_google_charts

#In method of controller

Default Chart or Hello World Chart
@chart = GoogleChart.new

Set the width of chart
@chart = GoogleLineChart.new :width => 300, :height => 200

Set the data
dataset = GoogleChartDataset.new :data => [10,50,4,10,16]
data = GoogleChartData.new :datasets => dataset
@chart = GoogleLineChart.new :width => 300, :height => 200
@chart.data = data

add a chart title
dataset = GoogleChartDataset.new :data => [10,50,4,10,16]
data = GoogleChartData.new :datasets => dataset
@chart = GoogleLineChart.new :width => 200, :height => 150, :title => ‘Java vs. Ruby Montly Job Opportunities’
@chart.data = data

Set title in array instead of string
dataset = GoogleChartDataset.new :data => [10,50,4,10,16]
data = GoogleChartData.new :datasets => dataset
@chart = GoogleLineChart.new :width => 200, :height => 150, :title => [‘Java vs. Ruby’, ‘Montly Job Opportunities’]
@chart.data = data

Multiple data in chart
dataset1 = GoogleChartDataset.new :data => [10,50,4,10,16]
dataset2 = GoogleChartDataset.new :data => [99, 81, 25, 54, 80]
data = GoogleChartData.new :datasets => [dataset1, dataset2]
@chart = GoogleLineChart.new :width => 200, :height => 150, :title => [‘Java vs. Ruby’, ‘Montly Job Opportunities’]
@chart.data = data

Add colors
dataset1 = GoogleChartDataset.new :data => [10,50,4,10,16],:color => ‘FF0000?
dataset2 = GoogleChartDataset.new :data =>[99,81,25,54,80],:color => ‘0000FF’
data = GoogleChartData.new :datasets => [dataset1, dataset2]
@chart = GoogleLineChart.new :width => 200, :height => 150, :title => [‘Java vs. Ruby’, ‘Montly Job Opportunities’]
@chart.data = data

Define legend
dataset1 = GoogleChartDataset.new :data =>[10,50,4,10,16],:color => ‘FF0000?, :title => ‘Java’
dataset2 = GoogleChartDataset.new :data=>[99,81,25,54,80],:color => ‘0000FF’, :title => ‘Ruby’
data = GoogleChartData.new :datasets => [dataset1, dataset2]
@chart = GoogleLineChart.new :width => 200, :height => 150, :title => [‘Java vs. Ruby’, ‘Montly Job Opportunities’]
@chart.data = data

Define Axis
dataset1 = GoogleChartDataset.new :data =>[10,50,4,10,16],:color => ‘FF0000?, :title => ‘Java’
dataset2 = GoogleChartDataset.new :data=>[99,81,25,54,80],:color => ‘0000FF’, :title => ‘Ruby’
data = GoogleChartData.new :datasets => [dataset1, dataset2]
axis = GoogleChartAxis.new :axis  => [GoogleChartAxis::LEFT, GoogleChartAxis::BOTTOM]
@chart = GoogleLineChart.new :width => 250, :height => 150, :title => [‘Java vs. Ruby’, ‘Montly Job Opportunities’]
@chart.data = data
@chart.axis = axis

Define Right and X Axis
dataset1 = GoogleChartDataset.new :data=> [10,50,4,10,16],:color => ‘FF0000?,  :title => ‘Java’
dataset2 = GoogleChartDataset.new :data=>[99,81,25,54,80],:color => ‘0000FF’, :title => ‘Ruby’
data = GoogleChartData.new :datasets => [dataset1, dataset2]
axis = GoogleChartAxis.new :axis  => [GoogleChartAxis::LEFT, GoogleChartAxis::BOTTOM,  GoogleChartAxis::RIGHT, GoogleChartAxis::BOTTOM]
@chart = GoogleLineChart.new :width => 300, :height => 200, :title => [‘Java vs. Ruby’, ‘Montly Job Opportunities’]
@chart.data = data
@chart.axis = axis

Define Bar Chart:
@chart = GoogleBarChart.new :width => 300, :height => 200, :title => [‘Java vs. Ruby’, ‘Montly Job Opportunities’]

Define 3D Pie Chart:
@chart = GooglePieChart.new :width => 400, :height => 200, :title => [‘Java vs. Ruby’, ‘Montly Job Opportunities’], :chart_type  => GooglePieChart::PIE_3D

#view:
<%= image_tag @chart.to_url %>

Be Sociable, Share!

Stress/Benchmark Testing on rails with httperf

Want to do benchmark or stress testing on your rails applications? Then look @ httpref

What is httpref?

Httperf is a tool for measuring web server performance. It provides a flexible facility for generating various HTTP workloads and for measuring server performance. The focus of httperf is not on implementing one particular benchmark but on providing a robust, high-performance tool that facilitates the construction of both micro- and macro-level benchmarks. The three distinguishing characteristics of httperf are its robustness, which includes the ability to generate and sustain server overload, support for the HTTP/1.1 and SSL protocols, and its extensibility to new workload generators and performance measurements.

Source url : – http://www.hpl.hp.com/research/linux/httperf/

Steps to do

1) download httpref from http://sourceforge.net/projects/httperf/

2) install the tool

3) check out commands on http://www.hpl.hp.com/research/linux/httperf/httperf-man-0.9.pdf

Thats all

Find out how many http requests your site can handle..

Njoi

For more info you can post comments here

Be Sociable, Share!

Export data to Excel (xls) in Ruby on Rails

The code Below will help to export the data in excel in Ruby on Rails

#Controller

class UserController < ApplicationController
  def export
    headers['Content-Type'] = "application/vnd.ms-excel"
    headers['Content-Disposition'] = 'attachment; filename="report.xls"'
    headers['Cache-Control'] = ''
    @users = User.find(:all)
  end

#View

export.html.erb

<%= link_to "Export as Excel", export_person_url %>

_report.html.erb

<table border="1">
  <tr>
    <th>Name</th>
  </tr>
  <% @users.each do |u| %>
  <tr>
   <td><%= u.name %></td>
  <% end %>
 </tr>
</table>

Please note :- This method might might be deprecated. You may visit http://spreadsheet.rubyforge.org/ for more info. Thanks

Be Sociable, Share!

Progress Bar in Rails

Ever thought of implementing a progress bar in rails? or did a need arise for you to do the same?

Something like if you want the user to show the progress bar while he is uploading the file and so on

Well there is a plugin available which will help you to do the same.. Here are the details for it

ProgressBar Plugin:

Install: ruby script/plugin install http://progressbarhelper.googlecode.com/svn/trunk/progress_bar_helper/

#View –

Include JS Files
<%=javascript_include_tag “progress_bar/jsProgressBarHandler.js”%>

Custom Static Progress Bar:
custom_static_progress_bar(name, value, options = {})

Options are:
# * name : used as an id for the progress bar
# * value : decimal value to represent (i.e. value <= 1)
# * options : rendering options
#
# Rendering options are:
# * show_text : set to true to display percentage value in a text form
# * animate : set to true to animate the image
# * width : sets the width of the image (!must be the same as the actual box_image width
# * height : sets the height of the image (!must be the same as the actual box_image height
# * box_image : sets the container image
# * bar_images : sets the progress bar images (must be an Array)

Example:
<%=custom_static_progress_bar(”a2?,1.0,{:show_text=>”Test”,:animate=>true,:width=>120,:height=>12})%>

Progress Bar:
progress_bar(name,value, display_percentage_text = false, multicolor = false)

Njoi A gr8 progress bar.

Thanks

Dhaval Parikh

http://www.dhavalparikh.co.in

Be Sociable, Share!

.htaccess protection with nginx

Hey just recently had a requirement where in I had to set password for my website. It was a ruby on rails website and I had to set .htaccess for it. I knew how to setup .htaccess for apache but with nginx (that our site was using as webserver) I didnt knew what to do.

Then I figured out the solution

Open nginx.conf file. Search for the location word you might see multiple location configuration. But put the code below in the root location

            auth_basic "RESTRICTED ACCESS";
            auth_basic_user_file /path/to/htpasswd/file

For ruby on rails it will be generally in
 the public folder of your rails app.

If you havent generated the htpassword 
yet pls do it using the following command 

htpasswd -b -c htpasswd username password

Hope this will be useful to you if you
 are caught in the same situation as me.

Njoi protecting the site
Be Sociable, Share!
1 5 6 7 8 9 27