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