Posted by tohchye
If you encounter the following error when you start your rails version 1.1.6 application and you are using ruby 1.8.6.
ArgumentError (wrong number of arguments (1 for 0)):
/usr/local/lib/ruby/gems/1.8/gems/activerecord-1.14.4/lib/active_record/vendor/mysql.rb:551:in `initialize'
/usr/local/lib/ruby/gems/1.8/gems/activerecord-1.14.4/lib/active_record/vendor/mysql.rb:551:in `new'
/usr/local/lib/ruby/gems/1.8/gems/activerecord-1.14.4/lib/active_record/vendor/mysql.rb:551:in `scramble41'
/usr/local/lib/ruby/gems/1.8/gems/activerecord-1.14.4/lib/active_record/vendor/mysql.rb:141:in `real_connect' /usr/local/lib/ruby/gems/1.8/gems/activerecord-1.14.4/lib/active_record/connection_adapters/mysql_adapter.rb:330:in `connect' /usr/local/lib/ruby/gems/1.8/gems/activerecord-1.14.4/lib/active_record/connection_adapters/mysql_adapter.rb:87:in `initialize'
it’s actually due to changes in Digest initialization method. The new method no longer supports instantiation with parameters. The offending code is in
/usr/local/lib/ruby/gems/1.8/gems/activerecord-1.14.4/lib/active_record/vendor/mysql.rb
at line 551 within method 'scramble41(password, message)'
s1 = Digest::SHA1.new(password).digest
s2 = Digest::SHA1.new(s1).digest
x = Digest::SHA1.(message + s2).digest
To resolve, just change the code to the following
s1 = Digest::SHA1.digest(password)
s2 = Digest::SHA1.digest(s1)
x = Digest::SHA1.digest(message + s2)
Alternatively you can upgrade your rails version to 1.2.x.
Posted by tohchye
I am going to write a series of post as I embark on my journey to create my own web 2.0 start up. I will not disclose what I’m working on at this moment, but I will write as much as I can on the tools, libraries and methods I will be using. Where possible I’ll list down the steps and my though process. I hope this can serve as a reference for anyone who wants to build his/her own web application using Rails.
Getting started
-
Domain name
This is one of the hardest part. To find a good domain name is difficult nowadays. Instant Domain Search is a very nice tool for searching domain. Lucky for me, I’m able to get hold of a good domain name for my app. (I will disclose my domain when it’s ready, in the mean time stay tuned)
-
Hardware and OS
I will be using my MacBook which is still running on Tiger at the moment. I would not be upgrading to Leopard in the near future and I think Tiger is good enough to do my work.
-
Text editor
I have been hacking in TextMate for some time and I love it. It’s shipped with Ruby and Rails bundles. Go ahead and download a trial version and give a try (only for Mac). If you are already hacking in TextMate, you may want to download the Textmate Vibrant Ink Theme and Prototype Bundle
Posted by tohchye
Autocomplete text field is a very useful feature to speed up form completion and help minimize errors. It’s even better if you can highlight the keywords within the dropdown list to help user search for the right choice. Here’s how to implement keyword highlighting in rails.

1. First add the necessary javascripts to make the text field into an autocomplete text field.
form
<%= text_field_tag 'country', '', :id => 'country' %>
<div id="country_autocomplete" style="display:none"></div>
<script type="text/javascript">
//<![CDATA[
var country_auto_completer = new Ajax.Autocompleter('country', 'country_auto_complete',
'/countries/auto_complete_for_country', frequency:0.2})
//]]>
</script>
2. Then in the controller add in the method to find the list of items base on the keywords and assign the keyword to an instance variable (this is needed for the highlighting).
controller
def auto_complete_for_country
@keyword = params[:country]
@countries = Country.find(:all, :conditions => ['name like ?', "%params[:country]%"])
render(:partial => 'auto_complete')
end
3. In the view, create the highlighting effect by replacing all keywords within the country names with ‘keyword’ using the ‘strong’ tag.
view (_auto_complete.rhtml)
<ul>
<% for country in @countries do -%>
<li><%=h(country.name).gsub(Regexp.new("(#{@keyword})", true), '<strong>\1</strong>') %></li>
</ul>
Posted by tohchye
I will be heading for my first coding competition (Code Xtreme Apps) tomorrow at SMU. It’s a 24hrs coding compeition and it’s the first of it’s kind in Singapore. I’m quite excited about it and looking forward to it. There are total of 73 teams and I believe it will be a tough fight with some of the best rails developer from Singapore and around the regions. Well I do hope I can win but mostly I’m taking it as more of an experience and fun kind of feeling to the competition.
Posted by tohchye
If you have been following our blog you should have read the post
Swiss Amry Knife 2.0
. We have recently switch our mail server to Google Apps. This is nice but that also means we have to change our ActionMailer server settings to GMail’s smtp server and this pose a problem. Because default ActionMailer does not support
SSL
authentication which is required by GMail. I tried searching for a solution and lucky enough I managed to came across this
post
and got to work! Check out the link if you are facing the same problem.