Friday, May 8, 2009

Some life updates

Actually this month is happening... as life is as usual.
Just resigned from MPST(MPS Technologies Limited) and am stretching my legs and thank god that even summers are chilling now-a-days so it is all very pleasant.
and I voted too this central elections (it is only applicable if you known about current Indian political status of India).
And ya the most happening thing that i did this week was i took the test drive of Toyota innova, and to be fare i thought i was disappointed for the gear knob vibrations from toyota but latter on, i thought every other car is only way behind it.... so why give it a bad name.. so it is good and perfect if you care about your family and wanna visit places.. it is a nice car that's for sure.
And as was expected, I also visited the tata showroom to ask in for tata most famous car after nano, exactly the safari The tata safari... and not going against my expectations, they didn't had any car to give the test drive and according to them they give test drive on vehicles which are ordered for other customers, now that's bad.
And here is a car comparison that i have not done before..
Innova is
  • good interiors
  • good exteriors
  • not so good vibrating gear in diesel
  • it doesn't rules the road
  • No 4*4 wheel drive
  • but very stable and great family car
  • Service is prompt i will buy innova if i can park it in near future

About Safari
  • "Reclaim you life" slogans fits in, but is life so lost??
  • Great exteriors and equally bad interiors
  • finish is not finished yet, come on guys increase the price by 2 lakhs but don't decrease the expectations
  • Why is roof mounted AC looks as if it is not part of roof (learn something from innova)
  • Service (Needs a big big improvement)
  • And please do have a separate car to test drive

:)

I was so mentally boosting myself to buy a safari but they have shattered my dreams, what to do and why to do!! both questions are playing

Any how people its late in night and that too of no-work... i want to fit my "Reclaim your sleep" slogan now.

bbye and good luck

Saturday, May 2, 2009

Pretty urls with name or title in ruby on rails

Hi folks,

Something on which is very old.. might not be very interesting for many of you who are into rails development. I am talking about the pretty-urls the SEO stuff(forget all this, it is for good readability of url).

So what my basic funda that i have gathered from last three years is that, every resource is identified by an identifier in rails(generally called id, in terms of database), but displaying the id doesn't sounds legal to me.. so to hide the ids and to have a nice looking readable

we can have title or name fields in the database's relation(table) and to make use of pretty urls, we make corresponding column like stripped_title or stripped_name.
create a file "make_pretty_url.rb" in initializers in config and append the following code.


puts "===================================================="
puts "Adding engine to make pretty url(s)"
puts "===================================================="
module ActiveRecord
class Base
after_create :make_or_update_pretty_url_name

def make_or_update_pretty_url_name
parent_column = nil
stripped_column = self.attributes.collect {|x| x.to_s.include?("stripped_") ? x : nil}.flatten.compact.first
if stripped_column
parent_column = stripped_column.gsub("stripped_","")
if self.send(parent_column)
self.send("#{stripped_column}=",stripp_it(self.send(parent_column)))
if self.class.find(:all, :conditions => ["#{stripped_column} = ?",self.send(stripped_column)]).length > 0
self.send("#{stripped_column}=","#{self.send(stripped_column)}-#{self.id.to_s}")
end
self.send("save")
end
end
end

def stripp_it(str)
str.strip.downcase.gsub(/[^a-z0-9]/,"-").gsub(/(-)+/,"-").gsub(/(-)+$/,"")
end
end
end


it will automatically create stripped_{column_name} and will take care of duplicates and instead of using find_by_id(), find_by_stripped_{column_name} will be used to get the resource and "make_or_update_pretty_url_name" method will also be available for any manual work too.

Hope this just adds in the knowledge base of stuff, and if there is anything about it, let me know through comments..

Honda Civic & A/C problems.

Hello Friends, Got a post again on to Honda Civic (The good old favorite commuter of mine). This car has been doing great except for so...