About ruby on rails, hackintosh, iphone3g and etc.

Monday, May 25, 2009

Hackintosh X61 (non-tablet) Upgrade to 10.5.7


Just upgraded my X61 hackintosh to 10.5.7. Upgrading process is easy. Nothing to take note all. No script required to run or delete any hidden kexts. Just use iDeneb 10.5.7 Upgrade Kit. Well done iDeneb team. It is similar to upgrading using Apple combo or delta update pack. Just run the installer and reboot twice and then 10.5.7 is installed.

To download iDeneb 10.5.7 Upgrade Kit, click here.


Monday, May 11, 2009

Rails link_to Previous Page

There is a useful shorthand in Ruby On Rails.

:back

< %= link_to "Back", :back % >

is equivalent to redirect_to(request.env["HTTP_REFERER"])


Saturday, May 9, 2009

Rails Autocomplete Plugin

To enable Rails Autocomplete Plugin, you need the following steps:

1. Install plugin:

script/plugin install auto_complete

2. Add this line to the controller where auto_complete to be used:

auto_complete_for :contact, :name

3. < %= text_field_with_auto_complete :contact, :name, { :size => 10 }, { :skip_style => false,
:method => :get} % >


Using :method => :get overcomes the problem with InvalidAuthenticityToken.

4. To customize the result, you can override a method in your controller.

def auto_complete_for_contact_name
@user = User.find_by_id(session[:user_id])
re = Regexp.new("^#{params[:contact][:name]}", "i")
find_options = {:conditions => ['company_id = ?', "#{@user.company_id}"],:order => "name ASC" }
@organizations = Contact.find(:all, find_options).collect(&:name).select { |org| org.match re }

render :inline => "< %= content_tag(:ul, @organizations.map { |org| content_tag(:li, h(org)) }) % >"
end


The example above shows that the result will be filtered by company_id and sorted by name.

5. To beauty the autocomplete results, the css below can be helpful.

div.auto_complete {
position:absolute;
width:250px;
background-color:white;
border:1px solid #888;
margin:0px;
padding:0px;
}
li.selected { background-color: #ffb; }

Friday, May 8, 2009

Using ISAPI Rewrite on Rails App with IIS and Mongrel as Windows Service

In setting up a multiple production environment in a single server, IIS alone cannot do the redirection of url nicely. When a RAILS app runs in IIS, it requires port number and to redirect domain name to the particular port number, ISAPI Rewrite can help. Below are some sample of how to redirect a hostname to the port required.

RewriteCond %{HTTP:Host} ^(?:www\.)?domain name\.biz$
RewriteRule (.*) http://www.domain name.biz:3000$1 [R=301,L]

RewriteCond %{HTTP:Host} ^(?:www\.)?another domain name\.com$
RewriteRule (.*) http://www.another domain name.com:3001$1 [R=301,L]

Updated: 27th May 2009
Possible to do URL masking by using rewrite proxy

RewriteCond %{HTTP:Host} ^(?:www\.)?another domain name\.com$
RewriteProxy (.*) http://localhost:4002$1

Note: it will map to localhost:4002 and transparent to user as the url shown is www.anotherdomainname.com. You can point multiple domain name to a single web app.

To get this done:
1. Install ISAPI Rewrite.
2. Copy and replace domain name to your own domain name in ISAPI rewrite.
3. If you have more than one domain pointing to the same server, just add below the first domain.