File upload

hum, the question is the file it’s represented in a model?

anyway, i used virtual attributes…

any questions, just ask =)

at sfile.rb

validate_on_create :validate_upload

def temp_file= temp_file

@temp_file = temp_file

end

protected

def validate_update

errors.add_to_base(“Upload a valid Flash file”) unless validate_type_file @temp_file

end

def validate_type_file file

original_filename = file.original_filename

extension = SFile.ret_ext_file original_filename

reg_file = Regexp.new(/(flw)/)

if n =~ reg_file

return true

else

return false

end

end

def self.ret_ext_file n

v = n.split(’.’)

v = v[v.size-1].downcase

return v

end

at .erb

Welcome

<% form_for(@sfile) do |f| %>
<%= f.error_messages %>

<%= f.label :title %>
<%= f.text_field :title %>

<%= f.label :description %>

<%= f.text_area :description %>

<%= file_field 'i', 'temp_file' %>

<%= f.submit 'Create' %>

<% end %>

at sfile_controller.rb

def create

            @sfile = Sfile.new(params[:sfile])

            @sfile.attributes = params[:i]
            respond_to do |format|
                    if @sfile.save
                            flash[:notice] = 'File was successfully created.'

                            format.html { redirect_to(@sfile) }
                    else
                            format.html { render :action => "new" }
                    end

            end

end