Will_paginate Customization

Will_paginate will give the neatful form of pagination as seen in the earlier. Here we can see the
the some customized form displaying the pagination displays,

<%= will_paginate @display_data %>

— will  display the normal pagination navigation icon as seen.

<%= will_paginate @display_data, :page_links => false %>

— will  display the normal previous and Next icon exlcuding the page numbers.


Find Record/Information Time Line

In Rails, we can find the last updated record date/time information with the current date/time information. This can be done as seen below,

def self.didwhen(old_time)
val = Time.now – old_time
if val < 10 then
result = ‘just a moment ago’
elsif val < 40  then
result = ‘less than ‘ + (val * 1.5).to_i.to_s.slice(0,1) + ‘0 seconds ago’
elsif val < 60 then
result = ‘less than a minute ago’
elsif val < 60 * 1.3  then
result = “1 minute ago”
elsif val < 60 * 50  then
result = “#{(val / 60).to_i} minutes ago”
elsif val < 60  * 60  * 1.4 then
result = ‘about 1 hour ago’
elsif val < 60  * 60 * (24 / 1.02) then
result = “about #{(val / 60 / 60 * 1.02).to_i} hours ago”
result =old_time.strftime(“%H:%M %p %B %d, %Y”)

By passing the created_dt value to the above function from the rails view section to get printed.The synatax is like,

<% timenow1 = ModelName.didwhen(tablename.created_at)    %>

Customized URL-Rewriting

In my rails application, i did custom URL rewrite since then my project navigation will look like this,

http://localhost:3000/   — redirecting to index page

For doing this you have to write  the map condition in your rails rout.rb files. The will be like this,

As in my application just want to show simplified custom url as above for that in the route.rb i wrote like this,

map.home ‘/home’,:controller=>”signup”, :action=>”update”

map.profile ‘/profile’,:controller=>”signup”, :action=>”profile”

In my view section for those  navigation, i.e link_to tage look like this,

<%= link_to “Home” , {:controller => “signup”, :action => “signup”} %>

<%= link_to “Profile” , {:controller => “signup”, :action => “profile”} %>

That’s all to get the desired Custom URL.


For more info on URL rewrite can get here :

Rails Booklet

Here is the quick guide to know the basic of Ruby on Rails. Please click the link to download,

Ruby on Rails Book-Let

find_by in rails

Using find_by method, we can have Database interaction on easy as like other language. In rails there are different types of find mehtods, they are


Used to find the particular the value with all the field in the row.

Used to find the particular the value specified in fieldname on the table.


3. find_by_sql():
This method will give the user to manage the query customization as the user like.

Signup.find_by_sql(“select * from signups where f.userid=’#{session[:user_id]}’ and s.id=f.followid limit 30”)

Capturing a value of a Key Press

Capturing the value of  keyboard each keys can done using Javascript. Here we can implement the Key Press event in the input box. we can find the value using the following function.

<input type=”text” name=”keyVal” id=”keyVal” keypress=”keyDown(event)” />

function keyDown(e)
// ie not case sensitive ?
dValues=”dKey=” + dKey+” dLet=” + dLet; alert(dValues);

The above function get invoked on each key press on the input box on the browser.



pagination_mainRuby on Rails pagination functionalities done by installing the simple will_paginate plugin. This can be installed by using the following  command executed on your ruby for Windows,

Once installed, you need to include the plugin library as

c:\wamp\Ruby>gem install will_paginate

require ‘will_paginate’

in the config/environment.rb bottom after the  below code in the  .rb file,

Rails::Initializer.run do |config|

Live pagination in code:

Add the below code in your model to access by all the controller methods,

def display_data
if (page!=”)
 paginate(:all,:page => page, :conditions => [“user_id = ?”, id], :per_page =>10)
 paginate(:all,:page => 1, :conditions => [“user_id = ?”, id], :per_page =>10)

call the below function in your controller to invoke the paginate from the disaply_data as follows,

  @display_data = MessageHistory.more_update(params[:date],params[:page],session[:user_id])

Now here we need to show the pagination in the User view, for that we need to add the below code to invoke the pagination from the controller.

 <%= will_paginate @display_data %>

 Thats all  We have Compeleted the pagination. Once the above run sucessfully you will get the pagination like in the below format on your web page.

For the CSS updates goto this links and copy the CSS  and place it in your project folder (public/stylesheet)


Floating Message Box

We can build a floating message box on fly in the browser depends on the scroll position of the window. This can be done using jquery simple few link code as seen below,

Here in the below code will fly message while on click  in submit button.Create a div tag, that going to become  a message box look on gly in the browser,

<div id=”message_box” ></div>



  $(“#message_box”).html(‘Settings Updated Sucessfully’); 
    $(‘#message_box’).animate({top:temp_sval+”px”,opacity:1 },{queue: false, duration: 350}); 
  $(‘#message_box’).animate({ top:”+=15px”,opacity:0 }, “slow”);



PHP-Stats is a complete view of your site’s accesses: in fact you can know what pages are visited by your users, and in what order they do it, moreover you can know from where they are referred (search engines, sites, etc.), verify what are the pages of greater interest, the time passed on your site and on every single page, verify the success of your aadvertising campaign and much much more… All this in totally free way!

More Info on the Stats can browse on this URL….

More on How to do can follow here,


What is JpGraph?

JpGraph is a Object-Oriented Graph creating library for PHP >= 4.3.1 The library is completely written in PHP and ready to be used in any PHP scripts (both CGI/APXS/CLI versions of PHP are supported).

The library can be used to create numerous types of graphs either on-line or written to a file. JpGraph makes it easy to draw both “quick and dirty” graphs with a minimum of code as well as complex graphs which requires a very fine grained control. The library assigns context sensitive default values for most of the parameters which minimizes the learning curve. The features are there when you need them – not as an obstacle to overcome!

More information on JGraph… http://www.aditus.nu/jpgraph/

« Older entries Newer entries »