Forum: Ruby on Rails Changing an attribute value

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
1b8a5e91cd9bc240910ac10f6a565843?d=identicon&s=25 Andrew Mansfield (Guest)
on 2007-04-21 00:17
(Received via mailing list)
I have a situation where I'm uploading a certain kind of file with an
arbitrary name e.g. "op10.out". I'm validating the file extension and
loading into a BLOB field in my database. These are small text files
containing NC machining code. I currently store the :filename,
:content_type and :data for each file in fields with those same names

I want to change the filename field from the original "op10.out" to
its program number which is stored in the :number field as something

I could probably discard the :filename and :content_type values, because
the former is redundant and the latter is dependant on whatever mime
type a
.out file is assigned to (usually "application/octet-stream" which
its a general binary type, is not very useful to validate on, at least

I copied the upload example from the "Skateboard" book, (2nd Ed.) but
uncertain what parameters get passed back to the to controller from the

How could I validate on the :filename value from the upload field in my
form but either discard the value or rename it to match the :number?

here's some code:


(the :name is created automatically and can't be changed)

<% form_for(:program, :url => {:action => 'update', :id => @program},
=> {:multipart => true}) do |form|%>

      -- other fields --

      <%= form.file_field :uploaded_file  %></p>
      <%= submit_tag "Submit Changes" %>
<% end %>

controller method

  def update
    @program = Program.find(params[:id])
    if @program.update_attributes(params[:program])
      flash[:notice] = 'Program was successfully updated.'
      redirect_to :action => 'show', :id => @program
      render :action => 'edit'


class Program < ActiveRecord::Base
  belongs_to :programmer
  belongs_to :edge
  belongs_to :router
  validates_presence_of :number, :description
  validates_uniqueness_of :number
  validates_format_of :filename,
                      :with => /.out$/,
                      :allow_nil => true,
                      :message => "-- you can only upload CNC .out
  def uploaded_file=(program_field)
    unless program_field.size == 0
      self.filename = base_part_of(program_field.original_filename)
      self.content_type = program_field.content_type.chomp =
  def base_part_of(file_name)
    File.basename(file_name).gsub(/[^\w._-]/, '')

I've always dumped form variables from php like the following:

while(list($key, $value) = each($_REQUEST)) {
      echo "$key ==> $value<br>\n";
      if(is_array($value)) {
            while(list($key1, $value1) = each($value)) {
                  echo " &nbsp $key1 ==> $value1<br>\n";
                  if(is_array($value1)) {
                        while(list($key2, $value2) = each($value1)) {
                              echo " &nbsp &nbsp $key2 ==>

is there a quick way of dumping form values to the browser in


Andrew Mansfield
Product Design & Development
Green Bay, WI

Print On-Demand Price Lists!  Accurate access, up-to-the minute pricing
documents 24/7. Web and print versions with new color addendum.
CONFIDENTIALITY NOTICE:  This e-mail, including attachments, is intended
solely for the person or entity to which it is addressed and may contain
confidential, privileged and/or proprietary information.  Any review,
dissemination, distribution, copying, printing, or other use of this
e-mail by persons or entities other than the addressee or his/her
authorized agent is prohibited. If you have received this e-mail in
error, please contact the sender immediately and delete the material
from your computer.
7b74ccf93dde7dd2ac5d2980d14fdc7b?d=identicon&s=25 Paul Lynch (plynchnlm)
on 2007-04-21 00:32
(Received via mailing list)
On Apr 20, 6:16 pm, "Andrew Mansfield" <>

> is there a quick way of dumping form values to the browser in Ruby/Rails?

I'm not sure of the answers to your other questions, but for this one,
have you tried:
    <%= debug(params) %>

8da92d4ed91aa12535f6d870fa76b25e?d=identicon&s=25 Aaron (Guest)
on 2007-04-21 00:41
(Received via mailing list)
> is there a quick way of dumping form values to the browser in Ruby/Rails?

I think the easiest way is to do a tail -f on the log file.  In
development mode the params from each request are written to the log
file.  Assuming the form is filing successfully there is no easy way
to display the params on a web page.  The create and update actions
save the record and then redirect to another action.  From the browser
you can only see the params from the redirect, not very interesting.
That said a great way to see params, the current session, and a bunch
of other stuff on any page is to install the textmate footnotes
plugin.  The features I mention work even if you don't use textmate.

888e0536d537efdd327f3a1c39335e4c?d=identicon&s=25 Christos Zisopoulos (Guest)
on 2007-04-21 16:02
(Received via mailing list)
Hello Andrew,

> is there a quick way of dumping form values to the browser in Ruby/
> Rails?


When running in development mode putting this in your controller

def myaction
   raise params

This topic is locked and can not be replied to.