Archive for August, 2008

How to fix “no file to load …” errors when installing Substruct shopping cart code

Posted in Uncategorized on August 26, 2008 by harryche2008

If you’re using substruct, and installing the code following the installation directions given on its website, you may run into problems like “no file to load xxx” errors when trying to initialize the databases by running:

rake substruct:db:bootstrap

The problem is that some of the files that come along with the source have wrong file extention names, like ../extract_options.rb0000644, which really should be ../extract_options.rb, without those weird numbers. I don’t know how it got in there. But once you corrected those file names, then everything should be fine.

How to setup a Subversion repository for a new project

Posted in web project on August 26, 2008 by harryche2008

To setup SVN for a New Project

1. Find a location for the SVN repository, then do:

svnadmin create path/to/repos

2. Add something to the repository for initial import. Create a directory “myproject”, then import it:

svn import -m “New import” myproject file:///path/to/repos/myproject

3. Start a new svnserve process for remove checkout/checkin:

svnserve -d –listen-port=3691 -r /path/to/repos

*note* default port is 3690, using different port allows you to setup svn for different projects on one server

4. Right click on a Windows folder, and do a checkout svn://ip_address:port/

5. Now add a new user to allow access to svn repository, edit /path/to/repos/conf/passwd file, add a line like:

user = userpwd

Then add or uncomment the lines in /path/to/repos/conf/svnserve.conf :

anon-access = none
auth-access = read
auth-access = write

password-db = passwd

Finally, restart the svnserve process.

How to get real self.id in :finder_sql

Posted in Ruby on Rails on August 11, 2008 by harryche2008

Sometimes you will have to use :finder_sql for complicated queries in an activerecord association, there is just simply no way around it. Now it’s important to get the calling model’s id, self.id, to construct correct SQL statements.

The problem is if you’re not careful, you will get weird id number for #{self.id}, which is actually the object_id, not the id from the database record.

The trick is not let #{self.id} to be evaluated immediately in the :finder_sql, but rather later when the whole sql is generated. For example, instead of using

:finder_sql => ".... t.user_id = #{self.id} ..."

use

'.... t.user_id = #{self.id} ...'

Notice it’s in single quote now. That will cause self.id to return the real id from the database, not the object_id.

Fix: Qmail virtualdomains pop3 not working

Posted in Qmail on August 9, 2008 by harryche2008

Sometimes, after setting up a pop3 account with qmail, everything seems working except that qmail doesn’t seem to be able to receive any emails sent to your new pop3 address. One common problem is with your pop boxes setup config file .qmail. Make sure in your .qmail file for that account has:

./Maildir/

Pay special attention to the trailing “/”, if absent, then it won’t work.

How to use multiple submit buttons for Ajax forms(form_remote)

Posted in Ruby on Rails on August 1, 2008 by harryche2008

The problem with form submission through an ajax remote call in Rails is that the Form.serialize doesn’t know which submit button is clicked, and it doesn’t include the value of the button clicked in the submission data.

There are many ways to do this, including extending the native Rails submit_tag helper, but the potential problem with that is all submit_tag will generate the extra code for handling the multiple submit buttons, which isn’t something you might want.

An easy way(especially you just have one or two forms that you need to do this) is to just add a hidden field in the form, and then in your extra submit button’s onclick event, set that hidden field value to whatever you want, so that in the controller end, you can just check for that hidden field.

Example:

 

<%= submit_tag “Save changes” %> <%= hidden_field_tag(:goal_status, “”) %> <%= submit_tag “Accomplished”, :o nclick => “$(‘goal_status’).value = ‘done’” %>