Archive for the ‘Ruby on Rails’ Category

h1 and undefined method self_and_descendants_from_active_record

September 9, 2009

We recently switched to rails 2.3.4 and noticed the following error:

undefined method self_and_descendants_from_active_record for Cart:Class

Our Cart class has no ActiveRecord binding, but we need some validations, so we simple use

@errors =

and overerride the valid? action.

But now we get the undefined method error.


Implement in your class also:

 def self.self_and_descendants_from_active_record

  def self.human_name(options = {})
    defaults = do |klass|
    defaults < [:activerecord, :models], :count => 1, :default => defaults}.merge(options))

  def self.human_attribute_name(attribute_key_name, options = {})
    defaults = do |klass|
    defaults << options[:default] if options[:default]
    defaults < defaults, :scope => [:activerecord, :attributes]))

and you can still use ActiveModel like validations 🙂


javascript value and rails I18n

September 8, 2009

Today i stumble about the following problem, i have a javascript value and want it inside a localized rails string.

„This is my string javascriptvalue and so on …“


'<%= T("This is my string ## and so on ...", :translate_string) %>'.sub(/##/, javascript_value);

i simple use javascript sub to replace ## with the javascript_value.



Switch to Mac

Mai 9, 2009

Vor einer Woche habe auch ich den Schritt zu Apple gewagt und mir ein „generalĂŒberholtes“ MacBook geleistet.

Im Moment bin ich noch am einrichten / konfigurieren / Programme suchen, aber alles in allem ist es doch schön eine voll funktionsfĂ€hige Konsole zur VerfĂŒgung zu haben und den komfort einer schönen OberflĂ€che.

Allen Rails Entwicklern sei der folgende Artikel ans Herz gelegt:

(Achtung: MySQL auch wirklich in der 32 Bit Version installieren!)

Als IDE empfehle ich Netbeans in der Version 6.7, auch wenn sich diese noch im Beta Stadium befindet.

So, und nun begebe ich mich noch auf die Suche nach einem einfachen Bildbearbeitungsprogramm 😉


CentOS and mod_rails – failed to map segment from shared object: Permission denied

April 6, 2009

After some playing with VirtualBox and CentOS i try to install mod_rails, all in all no big deal, but if i try to start / restart httpd service i got:

Stopping httpd: [FAILED]
Starting httpd: httpd: Syntax error on line 1of /etc/httpd/conf/
rails.conf: Cannot load /opt/ruby-enterprise/lib/ruby/gems/1.8/gems/
passenger-2.1.2/ext/apache2/ into server: /opt/ruby-
enterprise/lib/ruby/gems/1.8/gems/passenger-2.1.2/ext/apache2/ failed to map segment from shared object: Permission
denied [FAILED]

Disable SELinux, or have a closer look to the docs.


sortable_element with table

MĂ€rz 24, 2009
<table class="listing">
<tbody id="project_versions">
<% for item in project_versions %>
  <% content_tag_for(:tr, item) do %>
<td class="drag_handle">[drag]</td>
<td><%= h -%></span>
  <% end %>
<% end %>

 <%= sortable_element('project_versions', :url => {:controller => 'project', :action => 'sort_project_version'}, :handle => :drag_handle, :tag => :tr) %>

Without many words, i hope the code speaks for itself.
Take care of the :tag attriubte in the helper (default is li) and the container has to be the tbody.


Selling Rails in a Recession

MĂ€rz 5, 2009

According to this grailsblog post, here is the Rails port:

Open Source Stack = $0

Because Rails runs on the JVM (JRuby), it is platform agnostic and capable of running on top of a 100% open source stack. Everything including the OS, app server, and database may be obtained free of charge with no license fees.

Faster Development Time

Yes, it’s great that everything needed to run Rails’ applications may be obtained for free, but what’s even a bigger cost savings is how much time developers can save by working within the JRuby/Rails environment. Rails really tends to speed up development in the following 3 areas:

Data Access

ActiveRecord provides an amazingly efficient way to model domain objects as well as persist them to a database.


Scaffolding speeds up development time rapidly.


When working with JRuby and Rails, developers will find themselves writing less code than when working within the traditional Java environment. Less code translates into shorter development time.


Rails is a great fit for a recession. It allows developers to create high quality applications on top of a free open source stack in less time than many of the more common, corporate frameworks.


CentOS + VirtualBox + Ruby on Rails

Februar 7, 2009

Just some noticable Infos:

I installed VirtualBox ( and setup CentOS, for this i downloaded the complete image at (remember to copy the root password for the first login)

To start setup:
– change root password
– add an additional user
– update system files (yum update)
– install mysql (to use with ruby mysql gem you need to install also the developer packages)
– install ruby-enterprise (setup .bashrc)
– install subversion (yum install subversion)

Some useful infos:

Install Ruby Enterprise (including Rails):
Installing Ruby Enterprise on CentOS 5.2

Install MySQL Gem
Faild for me, so i found here the solution:
mysql gem on centos
Update: More Infos: Mysql gem centos5 hell

German Keyboard Layout
To change temporary (until reboot)
loadkeys de-latin1
And to verify that the keyboard layout is correct use the command: showkey

Permanent setting (CentOS):
Edit /etc/sysconfig/keyboard and replace KEYTABLE=“us“ by KEYTABLE=“de-latin1″
save and reboot.

To find whitch keyboard layout maps that is available is in the map
/lib/kbd/keymaps/i386/…depending on which distro is used.

Enable high resolution console:
As root, edit the file ‚/etc/grub.conf‘, and add ‚vga=XXX‘ to the line that begins with kernel.
Get other values here: VGA Screen Resolution

I will update this post, but for now i dont remember more steps 😉