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 action="create" method="post"
enctype="multipart/form-data">
  <p><input type="file" name="upload_file"
/></p>
  <p><input type="submit" name="Save"
value="Up load now"/></p>
</form>
<br/><br/>
<% form_for :form_file, :url => { :action => "create" },
:html => {
:multipart => true } do |g| %>
  <p><%= g.file_field :upload_file %>
  <p><%= submit_tag :Up_load_now %></p>
<% end %>
-- 
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
-~----------~----~----~----~------~----~------~--~---
On Nov 14, 2:45 pm, Nadeesha Meththananda <rails-mailing-l...@andreas- s.net> wrote:> 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 ????????? >Form_for is for object (when you pass activerecord object to view). Use form_tag instead. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
> f.write (@params["upload_file"].read);it''s params["upload_file"] not @params -- 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 -~----------~----~----~----~------~----~------~--~---
Thorsten Muller wrote:>> f.write (@params["upload_file"].read); > > it''s params["upload_file"] not @paramsthanks for the 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 -~----------~----~----~----~------~----~------~--~---
Akbar Home wrote:> On Nov 14, 2:45 pm, Nadeesha Meththananda <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. -- 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 -~----------~----~----~----~------~----~------~--~---
Nadeesha Meththananda wrote:> Akbar Home wrote: >> On Nov 14, 2:45 pm, Nadeesha Meththananda <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. -- 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 -~----------~----~----~----~------~----~------~--~---