Rails 2.1: send_file :x_sendfile => true

The “x_sendfile” argument on the send_file method in Rails 2.1 is not well thought off as it has an impact in development mode also. I guess most Rails coders won’t have Apache proxying their mongrels in dev mode and so they don’t get to see any images or files but the plain path information.

I’ll guess i stay with the x_send_file solution as described here.

| Comments (0) »

05-Jun-08


Oracle XE environment variables on Linux

Just a quick reminder for myself:

With the default installation of an Oracle Express (Oracle XE) comes two shell script with all the necessary environment variables to use sql*plus, exp, imp and the like on the command line:

source /usr/lib/oracle/xe/app/oracle/product/10.2.0/server/bin/oracle_env.sh

respectively

source /usr/lib/oracle/xe/app/oracle/product/10.2.0/server/bin/oracle_env.csh

| Comments (0) »

04-Jun-08


PDF::Writer and Ruby on Rails 2.1

Some days ago, Ruby On Rails 2.1 saw the light of day and as usual, i eagerly updated my Daily Fratze project.

I had some minor problems due to an old version of will_paginate and some major ones with my use of PDF::Writer.

The PDF::Writer library still works very well but the the instructions here (under PDF::Writer (Austin Ziegler) on how the register an “rpdf” template handler don’t apply anymore due to changes in the Rails template system but can easily be fixed:

In environment.rb change

ActionView::Base.register_template_handler 'rpdf', ActionView::PDFRender

to

ActionView::Template.register_template_handler 'rpdf', ActionView::PDFRender

And also change your ActionView::PDFRender class to:

module ActionView # :nodoc:
  require 'pdf/writer'
  class PDFRender
    PAPER = 'A4'
    include ApplicationHelper
    include ActionView::Helpers::AssetTagHelper
    include ActionView::Helpers::TextHelper      
    include ActionView::Helpers::TagHelper
    include ActionView::Helpers::UrlHelper
 
    def initialize(action_view)
      @action_view = action_view
    end
 
    # Render the PDF
    def render(template, local_assigns = {})
      @action_view.controller.headers["Content-Type"] ||= 'application/pdf'
 
      # Retrieve controller variables
      @action_view.controller.instance_variables.each do |v|
        instance_variable_set(v, @action_view.controller.instance_variable_get(v))
      end
 
      pdf = ::PDF::Writer.new( :paper => PAPER )
      pdf.compressed = true if RAILS_ENV != 'development'
      eval template.source, nil, "#{@action_view.base_path}/#{@action_view.first_render}.#{@action_view.finder.pick_template_extension(@action_view.first_render)}" 
 
      pdf.render
    end
 
    def self.compilable?
      false
    end
 
    def compilable?
      self.class.compilable?
    end
  end
end

And enjoy happy PDF generation 😉

| Comments (8) »

04-Jun-08


Hibernate and Inheritance Mapping

Hibernate supports multiple types of inheritance mapping, some of them (Table per class, Table per subclass) using a discriminator column to decide the class.

The type of the discriminator can be one of

string, character, integer, byte, short, boolean, yes_no, true_false

In case you need to use any other than string or character, i.e. integer, you have to give the base class a default discriminator-value like 0 or -1 or whatever fits, otherwise you’ll end up with a an exception like:

org.hibernate.MappingException: Could not format discriminator value to SQL string

as Hibernate uses the class name of the base class to derive a default value.

| Comments (0) »

27-May-08


Division by zero

Just a quick reminder for myself:

int a = 0/0; // Throws ArithmeticException
double d1 = 0/0.0; // d1 is NaN
double d2 = 1/0.0; // d2 is Infinity
double d3 = -1/0.0; // d3 is -Infinity

Can cause some headache if things fall apart in the JDBC driver and not before. Grmpf.

| Comments (0) »

26-May-08