Forum: Ruby on Rails File_column not keeping value during page reloads

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.
D9d1b31a337f46ac5e4dd56b55404f58?d=identicon&s=25 Dylan Markow (Guest)
on 2006-01-22 21:11
(Received via mailing list)
I'm trying to use the file_column plug-in to attach a file to a
newsletter posting. It works fine if I get the form right the first
time, but if I get an error, such as not typing in a required field, and
the form re-displays, my file selection box reverts to "no file
selected."

Here's my relevant controller code:

  def new
    @newsletterpost = Newsletterpost.new
  end

  def add_post
      @newsletterpost = Newsletterpost.new(params[:newsletterpost])
      @newsletterpost.user_id = @session[:user].id
      if @newsletterpost.save
          flash[:notice] = "Newsletter posting was successfully
created."
          redirect_to :action => 'list'
      else
          render :action => 'new'
      end
  end

And the relevant section from my _form.rhtml file:

    <label for='newsletterpost_filename'>Attachment:</label><br/>
    <%= file_column_field 'newsletterpost', 'filename' %> <br /><br />

And my newsletterpost model:

class Newsletterpost < ActiveRecord::Base
  belongs_to :user
  belongs_to :newslettercategory
  file_column :filename
  validates_presence_of :title
end



Any suggestions? Thanks!!
4bd34a2216dc8bdbf1f017f64e4d59e8?d=identicon&s=25 Kyle Maxwell (Guest)
on 2006-01-22 21:41
(Received via mailing list)
On 1/22/06, Dylan Markow <dylan@dylanmarkow.com> wrote:
>
>
>   file_column :filename
>
The file is prolly just being stored in the filename hidden field.  I
have found it useful to add some sort of notice beneath the
file_column_field to tell the user what is currently stored, because
the file_column_field definitely doesn't do that.  Something like:

<%=File.basename(@model.filename.to_s)%>

--
Kyle Maxwell
Chief Technologist
E Factor Media // FN Interactive
kyle@efactormedia.com
1-866-263-3261
B8ed55487e4f2f0feaeb68957dc07b21?d=identicon&s=25 Sebastian Kanthak (Guest)
on 2006-01-22 23:00
(Received via mailing list)
On 1/22/06, Dylan Markow <dylan@dylanmarkow.com> wrote:
> I'm trying to use the file_column plug-in to attach a file to a
> newsletter posting. It works fine if I get the form right the first
> time, but if I get an error, such as not typing in a required field, and
> the form re-displays, my file selection box reverts to "no file selected."

you can't do anything against this as pre-filling a file selection box
with a custom value would create quite a security issue. So you have
to create your own indication that a file has been uploaded, as Kyle
suggested.

Sebastian
This topic is locked and can not be replied to.