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!!
on 2006-01-22 21:11
on 2006-01-22 21:41
On 1/22/06, Dylan Markow <firstname.lastname@example.org> 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 email@example.com 1-866-263-3261
on 2006-01-22 23:00
On 1/22/06, Dylan Markow <firstname.lastname@example.org> 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