I used the following codes found in the net to use to write a file to
upload the files. down are the codes i have used. but still i did not
able to get the correct coding. so if somebody know where i have gone
wrong pls reply.
###################### IN the View #############################3
<form action="create" method="post"
enctype="multipart/form-data">
<p>
<b>Name:</b><br />
<%= text_field "person", "name" %>
</p>
<p>
<b>Picture:</b><br />
<input type="file" name="person[picture]" />
</p>
<p><input type="submit" name="Save"
/></p>
</form>
#################The controller:##########################
class AddressbookController < ApplicationController
def new
# not really needed since the template doesn''t rely on any data
end
def create
post = Post.save(@params["person"])
# Doesn''t this mean post is a File object?
# post.id is a bad idea in this case...
redirect_to :action => "show", :id => post.id
end
end
######### the model ###################
class Post < ActiveRecord::Base
def self.save(person)
f =
File.new("pictures/#{person[''name'']}/picture.jpg",
"wb")
f.write params[:picture].read
f.close
end
in the uploading it gives a error like this
undefined local variable or method `params'' for Post:Class
so i did some modification as
f.write params[:picture].read
line to
f.write (@params[:picture].read)
so the code woke properly, but still it gives a error saying
You have a nil object when you didn''t expect it!
You might have expected an instance of Array.
The error occurred while evaluating nil.[]
SO IF SOMEBODY KNOW HOW TO OVER COME THIS PROBLEM PLS REPLY
--
Posted via http://www.ruby-forum.com/.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---