Friday, December 31, 2010

mongrel and rails3

Trying to use rails3 with mongrel. It got error out.
Find this post: http://jan.varwig.org/archive/rails-3-and-mongrel

Put those lines into Gemfile
gem “mongrel”, “1.2.0.pre2″
gem “cgi_multipart_eof_fix”
gem “fastthread”

But using "mongrel_rails start" still not working.

It's fine when using "rails server" to start the mongrel_rails.

Thursday, December 30, 2010

gem install mysql2 fails.

It turn out need this package 'libmysqlclient-dev'.
Under Ubuntu 10.04 , 'sudo apt-get install libmysqlclient-dev'.

Wednesday, October 6, 2010

Know the different PATH_INFO

My rails application have root route to a store controller.
I need to know the user request sample.com or sample.com/store/local/12342 so I could show different text on the html title.
It could be done by using request.env["PATH_INFO"] to get the data.
If it is just plain sample.com it will return nil.

Clone Xen VM

I have been created an Xen VM. I want to clone it.
My enviroment is centos 5.4 with Dom0 installed.
And the original template vm is centos,too.
1. lvcreate -L 10G volGroup00 -n vm1
2. virt-clone --original vm_template --name vm1 --file /dev/VolGroup00/vm1 --force
3. edit /etc/sysconfig/network's hostname.
4. change ip if you don't want use dhcp.

Thursday, September 23, 2010

Legacy System Refactoring - 1. Middle Tier Data Acess

The Legacy System I work on is lots of JSP pages with POJO classes application. The business logic all spread on JSP pages and the POJO classes, thought it is east to start but it is hard to maintain. And the starter not me, I am the maintainer. Everytime I got new requirement, I feel not like to work on it. It took time to understand all the related , even unrelated topic , so that I could work on.

First step, I think adopt Middle Tier Data Access using JdbcTemplate should be easy way.

JdbcTemplate

Let me work on the products table.

1. Domain -- create Product domain class with get/setter methods.

2. DAO -- create ProductDao interface with CRUD methods.

3. JDBC DAO implementation -- public class JdbcProductDao extends SimpleJdbcDaoSupport implements ProductDao

4. ProductManager -- create ProductManager interface so you could group the product related methods together.

5. SimpleProductManager -- implementation of ProductManager interface.

6. Config applicationContext.xml -- specify dataSource, productDao, productManager bean.

7. Jsp pages get the productManager bean --
WebApplicationContext ctx = WebApplicationContextUtils.getRequiredWebApplicationContext(application);
ProductManager productManager = (ProductManager)ctx.getBean("productManager");

That's it. only 7 steps to Refactory that.

Thursday, September 16, 2010

jruby-rack error

After I deploy the war file created from warble to tomcat-5.5.27.
It gave me this error:
org.jruby.rack.RackInitializationException: java.lang.NoSuchMethodError: javax.servlet.ServletContext.getContextPath()Ljava/lang/String;

Goggling, someone sugguest downgrade to jruby-rack to 0.9.6.
But I can't install this version, it complain they can't find it.

Then I try to deploy to tomcat 6.0.29, it looks fine now. :)
It turn out the ServletContext.getContextPath() is in servlet 2.5 spec, tmcat-5.5 just servlet 2.4.

Reference:

Friday, March 26, 2010

options_for_select

I have two-element-array [["Credit Card","1",["Cash","2"] serves as options for a drop down box.

After post and error back to redisplay the page, the selected value didn't work. I know we need set the pre-selected value somewhere. But I really have no idea.

I am finally find this blog and know the answer is options_for_select helper.