Monday, August 21, 2006

LIKE as a condition to get records.

Here's a handy tip for Rails beginners: When you need to find records based on a condition that involves the use of LIKE '%value%' (it's going to be very slow since MySQL won't use an index for this query), try something like the following:

 @records = MyModel.find(:all, :conditions => ['col LIKE ? ', '%'+@term+'%'],:limit => 10)

Starting Webrick on a different port

Often you may need to start webrick on a different port. Luckily, you can do so using the -p options.

[root@srv31 ror]# ruby script/server -p 9191
=> Booting WEBrick...
=> Rails application started on
=> Ctrl-C to shutdown server; call with --help for options
[2006-08-21 13:45:37] INFO WEBrick 1.3.1
[2006-08-21 13:45:37] INFO ruby 1.8.4 (2005-12-24) [i686-linux]
[2006-08-21 13:45:37] INFO WEBrick::HTTPServer#start: pid=4812 port=9191

For more help options use the --help option:

[root@srv31 ror]# ruby script/server --help
=> Booting WEBrick...
Usage: ruby server [options]

-p, --port=port Runs Rails on the specified port.
Default: 3000
-b, --binding=ip Binds Rails to the specified ip.
-e, --environment=name Specifies the environment to run this server under (test/development/production).
Default: development
-m, --mime-types=filename Specifies an Apache style mime.types configuration file to be used for mime types
Default: none
-d, --daemon Make Rails run as a Daemon (only works if fork is available -- meaning on *nix).
-c, --charset=charset Set default charset for output.
Default: UTF-8

-h, --help Show this help message.

Sunday, August 06, 2006

ActiveRecord::Subclass Not found

If you ever get the following error:

The single-table inheritance mechanism failed to locate the subclass: 'link'. This error is raised because the column 'type' is reserved for storing the class in case of inheritance. Please rename this column if you didn't intend it to be used for storing the inheritance class or overwrite Olink.inheritance_column to use another column for that information.

Make sure you don't have a field named type in your table.

eXTReMe Tracker