Forum: Ruby on Rails file column inserts wrong file url field into database

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.
6c2498b6d0a484f48833286727dd9573?d=identicon&s=25 Amin Salahuddin (amin)
on 2006-03-27 05:59
Hello,
ive set up file column like so

Controller:

def entry
    @entry = Entry.new(@params[:entry])
        if @entry.save
          flash[:notice] = 'Product was successfully updated.'
        else
         flash[:notice] = '?'
        end
      end

Model:

file_column :image



View:

<%= form_tag({:action=>'entry', :id=> @entry }, :multipart => true)%>
<%= file_column_field "entry", "image" %></p>
 <%= submit_tag 'entry' %>
<%=  end_form_tag %>


It seems like when the form is submitted it commits the hidden
"image_temp" part of the multipart form instead of the "file" part.

and this is what happens.:

 Parameters: {"commit"=>"Upload", "action"=>"entry",
"controller"=>"entry", "entry"=>{"image_temp"=>"",
"image"=>#<File:/tmp/CGI22011.1>}}

  SQL    BEGIN
  SQL   INSERT INTO entries (`entry`, `image`) VALUES(NULL,
'ihavebeenthinkingaboutyoual.gif')
  SQL    COMMIT

so i end up with  null value for my entry object.


funny thing is if i put this in the entry view:
 <%=image_tag url_for_file_column "entry", "image"  %>
while submiting it from another .rhtml file, i get a correct path and
the image shows up. acutally the image uploads perfectly but the url
reference does not make it to the database.

im new to rails so im not exactly sure how to tackle this.
any help will be greatly appreciated.
THANKS.
6c2498b6d0a484f48833286727dd9573?d=identicon&s=25 Amin Salahuddin (amin)
on 2006-03-28 07:22
one more question. apart from the agile web book and the rails wiki is
there anywhere i can learn more about multi-part forms?
This topic is locked and can not be replied to.