Forum: Ruby on Rails file_column error: tmp file created but not actual

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Ea44be95206beef3c6943907079bec89?d=identicon&s=25 Tom Snow (tomx)
on 2006-01-19 10:21
(Received via mailing list)
Hi

When I submit the form with field_column, the actual
image is not
uploaded, only temp files are crreated and I dont see
actual file created and the image file name is not in
the database and  get "fieldWithErrors". Then if
submit again, the actual file in created and an
database record is generated.

Here is the log file. I print @params and @wallpaper.

I find the following:
1st time:
"image_temp"=>"", "image"=>#<File:/tmp/CGI9849.3>
2nd time:
"image_temp"=>"1137655234.461399.9849/Chic_Skype.jpg",
 "image"=>#<StringIO:0x408fb898>

I don't know why the image_temp and image are
different between the first time and the second time.
Why is there a file, called "/tmp/CGI9849.3"?
Do you know why?

Also, I see an extra column, "image_temp", is
generated when commiting to the database. I don't have
the column created in the table. Does that matter?

My environement is Ruby 1.84 on Red Hat linux 9.0 with
mysql 4.1.

Thanks in advance.

-Tom

log:
++++++++++++++++++++++++++++++++++++++++++++++++++++++
StudioController: missing default helper path
studio_helper


Processing StudioController#new_wallpaper (for
64.166.12.169 at 2006-01-18 23:20:12) [GET]
  Parameters: {"action"=>"new_wallpaper",
"controller"=>"studio"}
  Wallpaper Columns (0.001270)   SHOW FIELDS FROM
products
Rendering  within layouts/studio
Rendering studio/new_wallpaper
Completed in 0.03270 (30 reqs/sec) | Rendering:
0.01022 (31%) | DB: 0.00127 (3%) | 200 OK
[http://64.166.12.163/studio/new_wallpaper]
StudioController: missing default helper path
studio_helper


Processing StudioController#create_wallpaper (for
64.166.12.169 at 2006-01-18 23:20:34) [POST]
  Parameters: {"commit"=>"Create",
"wallpaper"=>{"downloads"=>"0", "date_created"=>"Wed
Jan 18 23:20:12 PST 2006", "price"=>"0.0",
"title"=>"test logger4", "date_available(1i)"=>"2006",
"image_temp"=>"", "date_available(2i)"=>"1",
"description"=>"test4", "date_available(3i)"=>"18",
"date_available(4i)"=>"23", "user_id"=>"1",
"image"=>#<File:/tmp/CGI9849.3>,
"date_available(5i)"=>"20"},
"action"=>"create_wallpaper", "controller"=>"studio"}
  Wallpaper Columns (0.001305)   SHOW FIELDS FROM
products
  SQL (0.000249)   BEGIN
  SQL (0.000194)   COMMIT
wallpaper.error++++++++++++++++++++++++
{"commit"=>"Create", "wallpaper"=>{"downloads"=>"0",
"date_created"=>"Wed Jan 18 23:20:12 PST 2006",
"price"=>"0.0", "title"=>"test logger4",
"date_available(1i)"=>"2006", "image_temp"=>"",
"date_available(2i)"=>"1", "description"=>"test4",
"date_available(3i)"=>"18",
"date_available(4i)"=>"23", "user_id"=>"1",
"image"=>#<File:/tmp/CGI9849.3>,
"date_available(5i)"=>"20"},
"action"=>"create_wallpaper", "controller"=>"studio"}
wallpaper.error++++++++++++++++++++++++
#<Wallpaper:0x40a37d24
@errors=#<ActiveRecord::Errors:0x40a053ec
@errors={"image"=>["invalid image", "invalid image"]},
@base=#<Wallpaper:0x40a37d24 ...>>,
@image_state=#<FileColumn::TempUploadedFile:0x40a14978
@filename="Chic_Skype.jpg", @attr="image",
@tmp_dir="1137655234.461399.9849",
@instance=#<Wallpaper:0x40a37d24 ...>,
@magick_errors=["invalid image"],
@dir="script/../config/../public/wallpaper/image/tmp/1137655234.461399.9849",
@just_uploaded=true, @options_method=:image_options>,
@attributes={"downloads"=>"0", "date_created"=>"Wed
Jan 18 23:20:12 PST 2006", "date_available"=>Wed Jan
18 23:20:00 PST 2006, "price"=>"0.0", "title"=>"test
logger4", "type"=>"Wallpaper", "approved"=>true,
"category_id"=>0, "description"=>"test4",
"content"=>"", "user_id"=>"1", "editor_rating"=>nil,
"image"=>"Chic_Skype.jpg", "user_rating"=>nil,
"last_download"=>nil}, @new_record=true>
wallpaper.error++++++++++++++++++++++++
Rendering studio/new_wallpaper within layouts/studio
Rendering studio/new_wallpaper
Completed in 0.08755 (11 reqs/sec) | DB: 0.00175 (1%)
| 200 OK
[http://64.166.12.163/studio/create_wallpaper]
StudioController: missing default helper path
studio_helper


Processing StudioController#create_wallpaper (for
64.166.12.169 at 2006-01-18 23:20:37) [POST]
  Parameters: {"commit"=>"Create",
"wallpaper"=>{"downloads"=>"0", "date_created"=>"Wed
Jan 18 23:20:34 PST 2006", "price"=>"0.0",
"title"=>"test logger4", "date_available(1i)"=>"2006",
"image_temp"=>"1137655234.461399.9849/Chic_Skype.jpg",
"date_available(2i)"=>"1", "description"=>"test4",
"date_available(3i)"=>"18",
"date_available(4i)"=>"23", "user_id"=>"1",
"image"=>#<StringIO:0x408fb898>,
"date_available(5i)"=>"20"},
"action"=>"create_wallpaper", "controller"=>"studio"}
  Wallpaper Columns (0.001250)   SHOW FIELDS FROM
products
  SQL (0.000214)   BEGIN
  SQL (0.000449)   INSERT INTO products (`downloads`,
`date_created`, `date_available`, `price`, `title`,
`type`, `approved`, `category_id`, `description`,
`content`, `editor_rating`, `user_id`, `image`,
`last_download`, `user_rating`) VALUES(0, '2006-01-18
23:20:34', '2006-01-18 23:20:00', 0.0, 'test logger4',
'Wallpaper', 1, 0, 'test4', '', NULL, 1,
'Chic_Skype.jpg', NULL, NULL)
  SQL (0.000211)   COMMIT
wallpaper.save++++++++++++++++++++++++
{"commit"=>"Create", "wallpaper"=>{"downloads"=>"0",
"date_created"=>"Wed Jan 18 23:20:34 PST 2006",
"price"=>"0.0", "title"=>"test logger4",
"date_available(1i)"=>"2006",
"image_temp"=>"1137655234.461399.9849/Chic_Skype.jpg",
"date_available(2i)"=>"1", "description"=>"test4",
"date_available(3i)"=>"18",
"date_available(4i)"=>"23", "user_id"=>"1",
"image"=>#<StringIO:0x408fb898>,
"date_available(5i)"=>"20"},
"action"=>"create_wallpaper", "controller"=>"studio"}
wallpaper. wallpaper++++++++++++++++++++++++
#<Wallpaper:0x408914e8
@errors=#<ActiveRecord::Errors:0x40886228 @errors={},
@base=#<Wallpaper:0x408914e8 ...>>,
@image_state=#<FileColumn::PermanentUploadedFile:0x4086dcdc
@filename="Chic_Skype.jpg", @attr="image",
@instance=#<Wallpaper:0x408914e8 ...>,
@dir="script/../config/../public/wallpaper/image/9",
@just_uploaded=nil, @options_method=:image_options>,
@attributes={"downloads"=>"0", "date_created"=>"Wed
Jan 18 23:20:34 PST 2006", "date_available"=>Wed Jan
18 23:20:00 PST 2006, "price"=>"0.0", "title"=>"test
logger4", "type"=>"Wallpaper", "id"=>9,
"approved"=>true, "category_id"=>0,
"description"=>"test4", "content"=>"", "user_id"=>"1",
"editor_rating"=>nil, "image"=>"Chic_Skype.jpg",
"user_rating"=>nil, "last_download"=>nil},
@new_record=false>
wallpaper.save++++++++++++++++++++++++
Redirected to
http://64.166.12.163:3000/studio/list_wallpaper
Completed in 0.01338 (74 reqs/sec) | DB: 0.00212 (15%)
| 302 Found
[http://64.166.12.163/studio/create_wallpaper]
StudioController: missing default helper path
studio_helper


Processing StudioController#list_wallpaper (for
64.166.12.169 at 2006-01-18 23:20:38) [GET]
  Parameters: {"action"=>"list_wallpaper",
"controller"=>"studio"}
  Wallpaper Columns (0.001301)   SHOW FIELDS FROM
products
  Wallpaper Load (0.001971)   SELECT * FROM products
WHERE (products.`user_id` = 1 ) AND ( (products.`type`
= 'Wallpaper' ) )
  Wallpaper Count (0.000479)   SELECT COUNT(*) FROM
products WHERE ( (products.`type` = 'Wallpaper' ) )
  Wallpaper Load (0.001916)   SELECT * FROM products
WHERE ( (products.`type` =
'Wallpaper' ) ) LIMIT 0, 10
Rendering  within layouts/studio
Rendering studio/list_wallpaper
Completed in 0.02817 (35 reqs/sec) | Rendering:
0.01485 (52%) | DB: 0.00567 (20%) | 200 OK
[http://64.166.12.163/studio/list_wallpaper]



Wallpaper.rb
++++++++++++++++++++++++++++++++++++++++++++++++++++
class Wallpaper < ActiveRecord::Base

   file_column :image, :magick => {
              :versions => {
                        "thumb" => "50x50",
                        "medium" => "640x480"
                        }
              }

  validates_presence_of     :title
  validates_presence_of     :description
#  validates_presence_of     :image
  validates_uniqueness_of   :title
#  validates_numericality_of :price
#  validates_format_of       :image_url,
#                            :with    =>
%r{^http:.+\.(gif|jpg|png)$}i,
#                            :message => "must be a
URL for a GIF, JPG, or PNG image"

  # Return a list of wallpapers we can sell (which
means they have to be
  # available). Show the most recently available
first.
  def self.salable_items
    find(:all,
         :conditions => "date_available <= now()",
         :order      => "date_available desc")
  end

  protected

  # Validate that the wallpaper price is a positive
Float.
  #def validate  #:doc:
  #  errors.add(:price, "should be positive") unless
price.nil? || price > 0.0
  #end

end

new.rhtml
+++++++++++++++++++++++++++++++++++++++++++
<h1>New wallpaper</h1>

<%= start_form_tag({:action => "create"}, :multipart
=> true) %>

<table>
 <tr>
  <td>Title:</td>
  <td> <%= text_field ("wallpaper", "title", "size" =>
40) %> </td>
 </tr>

 <tr>
  <td>Description:</td>
  <td> <%= text_area ("wallpaper","description",
"cols" => 40, "rows" => 5) %> </td>
 </tr>

 <tr>
  <td>Image:</td>
  <td> <%= file_column_field ("wallpaper", "image",
"size" => 200) %> </td>
 </tr>

<%= hidden_field("wallpaper", "price") %>
<%= hidden_field("wallpaper", "downloads") %>
<%= hidden_field("wallpaper", "user_id", "value" =>
session[:user_id]) %>

 <tr>
  <td>Date Available:</td>
  <td> <%= datetime_select("wallpaper",
"date_available") %> </td>
 </tr>

 <tr>
  <td></td>
  <td>
   <%= submit_tag "Create" %>
  </td>
 </tr>

</table>
<%= end_form_tag %>

<%= link_to 'Back', :action => 'list' %>
This topic is locked and can not be replied to.