About content_type

Hello:
I defined a mehod in a model like this:
def file=(file_field)#virtual attri is not same as access method
unless file_field=="" #manage not upload image
if file_field.content_type=~/^image/ &&
ensure_uniq_img("/images/users/"+file_field.original_filename)
#the not image file will not be upload
File.open("#{RAILS_ROOT}/public/images/users/#{file_field.original_filename}",“wb”)
{ |i| i.write(file_field.read)}
end
#show the error message
self.photo="/images/users/"+file_field.original_filename
end
end
##############
But when i select a file locally to upload a file,the browser alway
displays error saying:
undefined method `content_type’ for #String:0x4f3f9e0.

who can help me?

anyone can help me?

On Aug 5, 1:06 am, Guo Y. [email protected]
wrote:

anyone can help me?

Is the form set to multipart ?

Fred

Frederick C. wrote:

On Aug 5, 1:06�am, Guo Y. [email protected]
wrote:

anyone can help me?

Is the form set to multipart ?

Fred

I have set the multipart attr?

who can help me?

My form codes are following:

<%form_tag :action=>“register”,:method=>:post,:multipart=>true do-%>
<%=render(:partial=>“changing_user”,:object=>@user)-%>
<%end-%>.

who can help me?

On 5 Aug 2008, at 11:10, Guo Y. wrote:

My form codes are following:

<%form_tag :action=>“register”,:method=>:post,:multipart=>true do-%>
<%=render(:partial=>“changing_user”,:object=>@user)-%>
<%end-%>.

who can help me?

That doesn’t actually create a multipart form (check the html
generated).
When using form_tag like this, the first argument is the options used
to build the url to post to. The second parameter are the options for
the form itself, and this is where the multipart option does.
So you need something more like

<%form_tag( {:action=>“register”},:method=>:post,:multipart=>true) do-%>

<%form_tag( {:action=>“register”},:method=>:post,:multipart=>true) do-%>

Thank you.It is the brace that made the error.