MonthApril 2006

Conditional partials in Ruby on Rails

Have you ever wanted to include a partial in Ruby on Rails only if the partial file actually exists ? This can be handy e.g. if you want to be able to include a special menu (as a partial) for some controller actions based on the action name (controller.action_name) but don’t want to make a dummy partial for every action (which is normally needed since Rails will throw an error if it can’t find a partial).

The following example will render a partial contained in the file _.rhtml only if this file exists:

def render_menupartial
render_partial(controller.action_name) if FileTest.exist?(File.join(RAILS_ROOT, 'app', 'views',controller.controller_name,'_'+controller.action_name+'.rhtml'))
end

remember to call this from your view (or probably layout) like < %= render_menupartial %> instead of < % render_menupartial %>.

I know: basic stuff, but since I already used this basic functionality quite often I’m sure someone out there will find this useful.

Paging file error after copy W2K partition

After copying a Windows 2000 installation (differend disk/partition, same machine) you get the following error:

Your system has no paging file, or the paging file is too small.

Followed by instructions on how to change the paging file settings.

Unfortunately, after you clicked ‘OK’ and are waiting for the desktop to appear, you get the login screen again and are thus unable to login to your Windows installation.

Googling finds the following page: http://support.microsoft.com/kb/249321/.
This page mentions a number of possible solutions, none of which seem to be really feasible:

If however you have another partition that still works on the same machine (probably the source partition you copied) and you can access the ‘new’ installation partition from this one, you can try the following much easier solution:

  • Boot Windows using the working partition
  • Start Regedt32
  • Choose HKEY_LOCAL_MACHINE
  • Choose ‘File/Load Hive’ from the menu
  • Open on the new, faulty partition Windows\System32\Config\Software and give it a name (e.g. tmp) when asked
  • Perform the change as mentioned under 3. at http://support.microsoft.com/kb/249321/ in this ‘tmp’ hive
  • Choose ‘File/Unload Hive’ to save your changes

Try to reboot your new installation again. Hopefully it will work for you. At least it did for me.
Now, follow the instruction in http://support.microsoft.com/kb/q223188/ to restore the correct drive assignment.