Add default value on Insert

The following inserts a new product, no problem. Howeve, I have to prefix the filename with "\images\" so upon retrieval it will looki in the right directory.

How can I modify this code to append "\images\" to the filename column?

  def create     @product =[:product])     if       flash['notice'] = 'Product was successfully created.'     end   end

You can define a before_save callback in your model to call a function which will prepend "\images\".

def create      @product =[:product])      @product.filename = "\\images\\" + @product.filename      if        flash['notice'] = 'Product was successfully created.'      end    end

This approach might be problematic if you're creating new products in other actions or elsewhere in your rails app. Using before_save won't pose the same problem.