Saturday, September 17, 2005

Cheap Dependency Injection with Struts Chain

I recently found a situation where I wanted to change some inheritance into delegation for a Struts Action class. I needed to create a base delegate class to hold the common information that my struts actions needed. Struts chains was already being used so, I simply added an interface defining a setter for the base delegate object. In an object that was monitoring via the struts chain, I check to see if the action being called implements the Delegate Interface and if it does, I call its setter with a new Delegate Object. I have to say that even though I really don't care for struts, the Struts Chain is pretty cool.

Saturday, September 10, 2005

KUbuntu configuration tidbits

KUbuntu configurations:
  • KDM theme - Place the theme data where ever you like, then edit /etc/kde3/kdm/kdmrc and change the Theme line to point to your new theme

Wednesday, September 07, 2005

First Day of School

My oldest son had his first day of Kindergarten yesterday. He was extremely excited and had a good time. He already has a girl friend which only solidifies my assumptions that he was going to be a ladies man. :)

Saturday, September 03, 2005

I feel useful

I feel really useful today. I actually changed the faucet in my kids bathroom. The old one was leaking and was old so, I decided to change it out for a new one. I know it isn't much but, I am usually pretty useless when it comes to stuff like that. :)

Friday, September 02, 2005

Missing my family

My beautiful wife and kids have taken a trip to sunny (hot) California to enroll my oldest son into school so he can then return and go to school here in Nebraska. Sound odd? It is and its a long story.

Anyways, tonight when I was talking to my family on the phone, my youngest son did nothing but repeat "I luv u daddy".

Boy do I miss them!

Ruby on Rails - Editing multiple rows of data on one form

I think I may have poorly chosen my first application to learn Rails or maybe not...

I am trying to set up some simple profit-loss reports for our store Natures Paws.

Working with a legacy schema with Rails has been challenging but, I still have found Rails pleasing to use. Tonight, I ran into a situation where, I wanted to be able to update multiple line items in an order and update the model with this data. Rails was able to handle this so easily once I figured out what to do. (Thanks to the params hash dump shown on a Ruby exception page, I was able to figure out what I was doing wrong).

So, if a view has some code, iterating through some line items (each a row in a database table), like so

<% for @line in @profit_report.report_lines %>

<%= h @line.product_name %>
<%= text_field("line[]", 'wholesale_price', :size => 4, :maxsize => 4, :onchange => 'updateWholeSaleTotal(this.value);') %>
<%= text_field("line[]", 'ourshipping_price', :size => 4, :maxsize => 4) %>
<%= h @line.customer_price %>
<%= h @line.customer_shipping_price %>
<%= text_field("line[]", 'usps_price', :size => 4, :maxsize => 4) %>
<%= h @line.commission_paid %>

<% end %>

Then the Controller code can then update each lines in the model like so...

@params[:line].each do |idx, line|
report_line = ReportLine.find(idx)

I have to say that is pretty sweet.