Aug 19 2007

fieldWithErrors Overrides my CSS Field Classes

etienne @ 6:07 pm

When there are errors on a form, Rails will normally create a <DIV> element with the fieldWithErrors class wrapped around the fields input statement. If you have your own CSS class wrapped around a field this will be overridden by the fieldWithErrors <DIV> which is a pain.

I was searching for a solution when I found this post:

I’d like to say I came up with this, but I actually found it somewhere else.

I have the following inside my environment.rb file:

ActionView::Base.field_error_proc = do |html_tag, instance|
  msg = instance.error_message
  error_style = "background-color: #f2afaf"
  if html_tag =~ /<(input|textarea|select)[^>]+style=/
    style_attribute = html_tag =~ /style=[’"]/
    html_tag.insert(style_attribute + 7, "#{error_style}; ")
  elsif html_tag =~ /<(input|textarea|select)/
    first_whitespace = html_tag =~ /\s/
    html_tag[first_whitespace] = " style=’#{error_style}’ "

I now get the desired effect when an error occurs, in my case it changes the background color of the field red, you can change it to whatever effect you want without it interfering with your field CSS classes…perfect!

Aug 11 2007

Ruby Classes and Objects, being Self Aware

etienne @ 3:43 pm

I’m currently writing an article on Ruby’s approach to objects, classes and also the use of self. Coming from a C++ background it has taken me sometime to grasp the Ruby way of doing things.

I’m doing it for a number of reasons, I want to enforce in my own mind the things that I have been learning, I find writing them down helps a lot. I also want to use it as a reference in the future as I’m sure I’ll forgot things down the track, also someone else may find it useful.

So look for Part 1 in a few days.


Aug 11 2007

More plugins

etienne @ 3:34 pm

Added some more plugins today:


Tag: plugins

Aug 11 2007

My first post

etienne @ 12:06 pm

I’ve been wanting to setup a blog for a long time but never quite got around to it, until now. I’m using WordPress as it was compatible with the components on my host server, and seems very popular. It was simple to setup and install, I’m using a wonderful template developed by Tommaso Baldovino. I originally looked at  mephisto but the server that hosts this blog did not have the required components. I’ve installed a few plugins while I was setting it all up including:

I work as a freelance developer using a number of development tools including C++, PHP, Ruby, and Rails.

Tag: Rails, Ruby

« Previous Page