# File\_column not keeping value during page reloads

**URL:** <https://www.ruby-forum.com/t/file-column-not-keeping-value-during-page-reloads/53012>\
**Category:** Rails\
**Created:** [January 22, 2006, 9:11pm UTC](https://www.ruby-forum.com/t/file-column-not-keeping-value-during-page-reloads/53012 "2006-01-22T21:11:14Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![dmarkow](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/bc8723/32.png) [@dmarkow](https://www.ruby-forum.com/u/dmarkow)\
**Post date:** [January 22, 2006, 9:11pm UTC](https://www.ruby-forum.com/t/file-column-not-keeping-value-during-page-reloads/53012/1 "2006-01-22T21:11:14Z")

</div>

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!!

---

<div class="post-metadata">

**Author:** ![dmarkow](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/bc8723/32.png) [@dmarkow](https://www.ruby-forum.com/u/dmarkow)\
**Post date:** [January 22, 2006, 9:41pm UTC](https://www.ruby-forum.com/t/file-column-not-keeping-value-during-page-reloads/53012/2 "2006-01-22T21:41:42Z")

</div>

On 1/22/06, Dylan M. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) 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 M.  
Chief Technologist  
E Factor Media // FN Interactive  
removed\_email\_address@domain.invalid  
1-866-263-3261

---

<div class="post-metadata">

**Author:** ![dmarkow](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/bc8723/32.png) [@dmarkow](https://www.ruby-forum.com/u/dmarkow)\
**Post date:** [January 22, 2006, 11:00pm UTC](https://www.ruby-forum.com/t/file-column-not-keeping-value-during-page-reloads/53012/3 "2006-01-22T23:00:50Z")

</div>

On 1/22/06, Dylan M. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) 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
