Archive for the ‘Rails’ Category
Getting back to the drawing board…
August 3rd, 2008

Drawing boards are so much more fun than paper’n pencil ![]()
Posted in ApnaBill, OpenSocial, Rails, Ruby, Startups, Web 2.0 | Comments (0)
LITBox helper for Rails
April 24th, 2008
Introducing - LITBox Helper for Rails!
Disclaimer: This is a work in progress and is available on “as is” basis.
For long, I was trying to integrate Criag Ambros’s RedBox plugin into ApnaBill.com project for implementing modal dialogs but somehow, the CSS always used to get upset, rendering the lightbox in such a way that the content which is to be shown inside it, shows below it.
Then I came across Ryan J Lowe’s LITBox(The site seems to down, try Google cache)- and boy, it rocks! Just 10 seconds setup, very light weight and looks brilliant! The code is nicely written too. But the only drawback was that it was plain JS stuff - so that means no Rails helpers available.
So, once the test implementation was done with, I decided to write a small helper myself. I’ve seen how Jorge’s Prototype Window Class’s rails helper works - so decided to base my code on the same lines. And since he’s already written the Ruby->JS part for converting between optional arguments, this didn’t seemed a daunting task even for a Wednesday night
-
-
# Based on Prototype Window Class Helper (http://pwc-helper.xurdeonrails.com)
-
-
module LitboxHelper
-
-
def params_for_javascript(params) #options_for_javascript doesn’t works fine
-
‘{’ + params.map {|k, v| "#{k}: #{
-
case v
-
when Hash then params_for_javascript( v )
-
when String then "‘#{v}’"
-
else v #Isn’t neither Hash or String
-
end }"}.sort.join(‘, ‘) + ‘}’
-
end
-
-
-
# Returns a default LITBox window.
-
def litbox_window(link_text, href, html_options={}, params={})
-
prefix = "<a "
-
# Add all html options as key="value" pairs
-
html_options.each do |k, v|
-
prefix += "#{k}=\"#{v}\" "
-
end
-
prefix += "href=\"javascript:void(null);\" onclick=\""
-
-
# JS Payload
-
payload = "new LITBox(’#{href}’, #{params_for_javascript(params)});"
-
-
# Rest of the stuff including link text
-
suffix = "\">#{link_text}</a>"
-
-
return prefix + payload + suffix
-
end
-
-
end
I’m trying to make it feature complete so that I can make it available for download.
Till then… happy hacking!
Posted in ApnaBill, Rails, Ruby, Web 2.0 | Comments (5)
Back to the basics - validating HTML anyone?
April 19th, 2008
Its almost 4 AM now & past 3 hours saw a lot of commits going into ApnaBill.com code. After realizing that we were not generating (X)HTML code, the effort was targeted at containment, if not eradication
Many thanks to Zundra for pointing this out to me.
Due to an open div tag, the new (& slick looking) navbar wasn’t showing up on IE. HTML cleanup frenzy atleast solved that problem…
Here is what’ve changed in the code so far (straight out of our changelog)
- Fixed a typo in recharge layout, a div tag was left open…
- Added type=text/css attribute to many style tags.
- Corrected CSS markups, removed dups.
- Added type=text/javascript attribute
- Cleaned up recharge layout, removed closing slash in self ending tags.
- Moved critical developer comments into ruby comments
- Moved hover box font=+2 to CSS
- Added invite section to navbar, removed the top-left badge.
Phew! Thats enough work for the night… onto some hollywood flick now!
Oh yes, btw, tomorrow’s a pretty hectic day. I’m watching “Horton Hears a Who” at 11AM, then going for LCG Meet at 3PM and meeting folks from www.entrip.com at 6PM. Wow! Now thats some schedule!
Posted in ApnaBill, Rails, Startups, Web 2.0 | Comments (2)
Migrating ApnaBill.com to SqlSessionStore
April 5th, 2008
Rails2’s client side sessions were starting to give us troubles as we were ‘kinda’ overshooting the 4kb limit almost every now and then. Idealists would say that thats a bad practice - and I agree - but the changes now run too deep to fix them, withought having to change/throw a lot of code.
It seemed much better to fall back to server side sessions than client side. A quick search and ActiveRecordStore is one of the chosen techniques after PStore. Another quick search and you’ll come across SqlSessionStore which is much faster than ActiveRecordStore. [Comparison of various session management techniques]
Installation and configuration was super quick (thanks to the plugin) - follow the README.
However, one issue that you’ll need to address is to get mysql-ruby installed.
The next issue that’ll stare at you in the face is to constantly keep the sessions table cleaned up. And I faced a peculiar problem solving this. The timestamps of “updated_at” were running 4 hours behind the Time.now value. So stock solutions available for this problem were not working perfectly. I had to subtract an offset of “4.hours” from XX.minutes.ago value to get the correct timeouts.
desc "Cleans up stale sessions." task :clean_stale_sessions => :environment do # Determined by manual inspection. offset = 4.hours CGI::Session::ActiveRecordStore::Session.destroy_all( ['updated_at <?', YOUR_TIMEOUT.minutes.ago - offset] ) end
Hence Solved Bug #69, which solved Bug #67 and Bug #15 - wheehaa!
Posted in ApnaBill, Rails, Startups, Web 2.0 | Comments (0)
YSlow ApnaBill.com ?
March 22nd, 2008
We just finished porting ApnaBill.com from Rails 1.2.5 to Rails 2.0.2 - the port wasn’t that tough, specially with Ben’s Rails2 Upgrade Notes on SlashDotDash.
The steps we took…
- Make your config file reflect the new rails version (make sure you have it installed)
- Move all instances of start_form_tag to form_tag
- Change find_all to find(:all)… this wasn’t an issue with us
- Take care of @session stuff - Rails2 uses session and header instead of @session and @header
With Rails2, comes the caching options for your assets - mainly JS and CSS assets. Checkout changeset 6164 for more details - but somehow combining all css/js into single files at runtime was taking more time than loading them separately in succession. Hence I switched back to asset_packager plugin by Scott Becker - and boy, it works like a charm! It churns out a combined (white-spaces removed) combined css and js files in production mode, while keeping them separately in development mode.


JS and CSS in development mode.

![]()
JS and CSS in production code
And thanks to YSlow, I managed to squeeze a bit more of speed into rendering of the page by moving JS content to as low in the HTML content as possible. As explained by YSlow, CSS should be kept at the top of your HTML while JS as low as possible - reason being - only CSS (most of the times) is required to render the page correctly. So why waste time fetching JS content when it’ll not be needed till the page is fully rendered…

Manage to pimp ApnaBill.com’s YSlow performance grade to D (65) from below 45
Next in queue is how to manage GZip headers in the HTTP requests from ApnaBill.com
Posted in ApnaBill, Rails | Comments (0)