Date sorting(ruby) from array is easy if array contain strings with proper date formats. Sometime invalid date formats raise argument error.
Sample i have used for date column attribute as follows.
def sort_on_mature_date(listings)
listings.sort do |x,y|
x_matures_on = x.when_does_it_mature? #date type
y_matures_on = y.when_does_it_mature? #date type
begin Date.parse(x_matures_on) rescue x_matures_on="1900-1-1" end #string could be not a date like "now"
begin Date.parse(y_matures_on) rescue y_matures_on="1900-1-1" end
Date.parse(x_matures_on)<=>Date.parse(y_matures_on)
end
end
You want Ruby? We can do it! Hire us for Ruby on Rails, CoffeeScript, BackBone.js, MongoDb, _underscore.js,dojo,Extjs,jQuery,Node.js,LAMP, AJAX info {at} rubyassist {dot} com
Friday, November 05, 2010
Friday, October 22, 2010
Rails rounded corner box helper
Here is the helper include in your rails app. You need to take care of images .
#usage:
<%top = {"background-image"=>"url('/images/accept_box_top.png')",:height=>"6px",:width=>"328px"}%>
<%mid = {"background-image"=>"url('/images/accept_box_mid.png')",:height=>"405px",:width=>"auto"}%>
<%bottom = {"background-image"=>"url('/images/accept_box_bottom.png')",:height=>"9px",:width=>"auto"}%>
<%content = {"padding"=>"15px 28px 22px 26px"}%>
<%=round_box(top,mid,bottom,content){|f| "nice box"} %>
Make sure that you pass right height and width. It automatically renders the box and content inside.
If you want you also add extra css attributes too!
#usage:
<%top = {"background-image"=>"url('/images/accept_box_top.png')",:height=>"6px",:width=>"328px"}%>
<%mid = {"background-image"=>"url('/images/accept_box_mid.png')",:height=>"405px",:width=>"auto"}%>
<%bottom = {"background-image"=>"url('/images/accept_box_bottom.png')",:height=>"9px",:width=>"auto"}%>
<%content = {"padding"=>"15px 28px 22px 26px"}%>
<%=round_box(top,mid,bottom,content){|f| "nice box"} %>
Make sure that you pass right height and width. It automatically renders the box and content inside.
If you want you also add extra css attributes too!
#round_box_helper.rb
module RoundBoxHelper
def round_box(top, mid,bottom,content,&b)
css_elements( top,mid,bottom,content)+
"<div class = 'accept_gift_box'>
<div class='accept_gift_box_top'></div>
<div class='accept_gift_box_mid'>
<div
class='accept_gift_box_content'>
"+b.call+"
</div>
</div>
<div class='accept_gift_box_bottom'> </div>
</div>"
end
def css_elements top,mid,bottom,content
"<style type='text/css'> " +
".accept_gift_box_top{"+
parse_styles( top )+
"}"+
".accept_gift_box_mid{"+
parse_styles( mid )+
"}"+
".accept_gift_box_bottom{"+
parse_styles( bottom )+
"}"+
".accept_gift_box_content{"+
parse_styles( content )+
"}"+
".accept_gift_box{"+
"float:left;"+
"}"+
"</style>"
end
def parse_styles el
str=""
el.each_pair do |attr,value|
str = str+attr.to_s+":"+value.to_s+";"
end
str
end
end
module RoundBoxHelper
def round_box(top, mid,bottom,content,&b)
css_elements( top,mid,bottom,content)+
"<div class = 'accept_gift_box'>
<div class='accept_gift_box_top'></div>
<div class='accept_gift_box_mid'>
<div
class='accept_gift_box_content'>
"+b.call+"
</div>
</div>
<div class='accept_gift_box_bottom'> </div>
</div>"
end
def css_elements top,mid,bottom,content
"<style type='text/css'> " +
".accept_gift_box_top{"+
parse_styles( top )+
"}"+
".accept_gift_box_mid{"+
parse_styles( mid )+
"}"+
".accept_gift_box_bottom{"+
parse_styles( bottom )+
"}"+
".accept_gift_box_content{"+
parse_styles( content )+
"}"+
".accept_gift_box{"+
"float:left;"+
"}"+
"</style>"
end
def parse_styles el
str=""
el.each_pair do |attr,value|
str = str+attr.to_s+":"+value.to_s+";"
end
str
end
end
Tuesday, September 28, 2010
width and top of invisible element in IE may give 0 zero using jQuery
jQuery element width for invisible element in IE will not give exact result.
But in Firefox it works perfectly.
$(e).width() //using jQuery to get the width.
i have used a way to solve this one by showing, calculate width and hiding the element.
$(e).
show(). // to get the width of visible element ==> IE issue
css({zoom: 1,left:$(e).position().left-parseInt($(e).width()),top:$(e).position().top}).
hide().
But in Firefox it works perfectly.
$(e).width() //using jQuery to get the width.
i have used a way to solve this one by showing, calculate width and hiding the element.
$(e).
show(). // to get the width of visible element ==> IE issue
css({zoom: 1,left:$(e).position().left-parseInt($(e).width()),top:$(e).position().top}).
hide().
jQuery animation effect slide bug in IE 7
The best example is for this ind of bug is presented by ryan as follows
http://www.ryancramer.com/misc/jquery_slide/#
the slide effects of jquery may not work 100% correctly in IE 6 & IE 7 . Effects are misbehave like effects complete till 50% or so...
So i have used show call back function to rescue the bug.. Though it is 100% not correct but once the effects renders second time it works perfectly.
So make it show and show it again..with less duration.. to avoid flickering effect.
$("my_element").show(1,function(){$(this).show("slide",{direction:"right"})})
http://www.ryancramer.com/misc/jquery_slide/#
the slide effects of jquery may not work 100% correctly in IE 6 & IE 7 . Effects are misbehave like effects complete till 50% or so...
So i have used show call back function to rescue the bug.. Though it is 100% not correct but once the effects renders second time it works perfectly.
So make it show and show it again..with less duration.. to avoid flickering effect.
$("my_element").show(1,function(){$(this).show("slide",{direction:"right"})})
Subscribe to:
Posts (Atom)