Problem in file uploading

i wote a code to do file uploading with the hep given in documents in
the net.
but i came across some problems.

in the View section the form that was wrote in th normal HTML was
working 100% perfect and it uplodes the files also.

but when i edited that in the rails way (u can see the coding in the
second form tag), when i goes to upload the file it give a error as this

" You have a nil object when you didn’t expect it!
The error occurred while evaluating nil.read"

so if any body know where i have gone wrong ???

######### wrote in the controller page #######################33

def create

f = File.new("./uploads/data.doc", "wb");
f.write (@params["upload_file"].read);
f.close;

render_action 'success'

end

#################### wrote in the view ###################



<% form_for :form_file, :url => { :action => “create” }, :html => {
:multipart => true } do |g| %>

<%= g.file_field :upload_file %>

<%= submit_tag :Up_load_now %>

<% end %>

On Nov 14, 2:45 pm, Nadeesha M. <rails-mailing-l…@andreas-
s.net> wrote:

" You have a nil object when you didn’t expect it!
The error occurred while evaluating nil.read"

so if any body know where i have gone wrong ???

Form_for is for object (when you pass activerecord object to view).
Use form_tag instead.

f.write (@params["upload_file"].read);

it’s params[“upload_file”] not @params

Thorsten M. wrote:

f.write (@params["upload_file"].read);

it’s params[“upload_file”] not @params

thanks for the reply.

Akbar H. wrote:

On Nov 14, 2:45 pm, Nadeesha M. <rails-mailing-l…@andreas-
s.net> wrote:

" You have a nil object when you didn’t expect it!
The error occurred while evaluating nil.read"

so if any body know where i have gone wrong ???

Form_for is for object (when you pass activerecord object to view).
Use form_tag instead.

sort it out the problem thanks.

by the way do u guys know any command to check the file format.

eg like .doc, .pdf .jpg.

Nadeesha M. wrote:

Akbar H. wrote:

On Nov 14, 2:45 pm, Nadeesha M. <rails-mailing-l…@andreas-
s.net> wrote:

" You have a nil object when you didn’t expect it!
The error occurred while evaluating nil.read"

so if any body know where i have gone wrong ???

Form_for is for object (when you pass activerecord object to view).
Use form_tag instead.

sort it out the problem thanks.

by the way do u guys know any command to check the file format.

eg like .doc, .pdf .jpg.

I think you can use

params[“upload_file”].content_type to check the file format

eg.

params[“upload_file”].content_type.chomp !~ /^image/

to check the upload file is image.