when i tried to crate an upload file application in rails i am getting error like this Template is missing Missing template app\views\upload\uploadfile.html.erb in view path app/views this is ma model class DataFile < ActiveRecord::Base def self.save(upload) name = upload[''datafile''].original_filename directory = "public/data" # create the file path path = File.join(directory, name) # write the file File.open(path, "wb") { |f| f.write(upload[''datafile''].read) } end end this is ma view file <h1>File Upload</h1> <%= start_form_tag ({:action => ''uploadFile''}, :multipart => true) %> <p><label for="upload_file">Select File</label> : <%= file_field ''upload'', ''datafile'' %></p> <%= submit_tag "Upload" %> <%= end_form_tag %> This is ma controller class UploadController < ApplicationController def index puts ''hiiiiiiiiiii'' render :file => ''app\views\upload\uploadfile.html.erb'' puts ''hiiiiiiiiiii2'' end def uploadFile puts ''hiiiiiiiiiii3'' post = DataFile.save(params[:upload]) render :text => "File has been uploaded successfully" end 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
I think use *render :file => ''uploadfile.html.erb''*, as rails would look for the template in your view directory, which is "app/views", and if you use render :file => ''controller/uploadfile.html.erb'', it will look for the template in "app/views/controller/uploadfile.html.erb", or rails always assume you have already put your template in the controller''s according view folder On Mon, Mar 29, 2010 at 12:41 PM, Tony Augustine <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org>wrote:> when i tried to crate an upload file application in rails i am getting > error like this > > > Template is missing > > Missing template app\views\upload\uploadfile.html.erb in view path > app/views > > this is ma model > > > class DataFile < ActiveRecord::Base > def self.save(upload) > name = upload[''datafile''].original_filename > directory = "public/data" > # create the file path > path = File.join(directory, name) > # write the file > File.open(path, "wb") { |f| f.write(upload[''datafile''].read) } > end > end > > > > > this is ma view file > > > <h1>File Upload</h1> > <%= start_form_tag ({:action => ''uploadFile''}, > :multipart => true) %> > <p><label for="upload_file">Select File</label> : > <%= file_field ''upload'', ''datafile'' %></p> > <%= submit_tag "Upload" %> > <%= end_form_tag %> > > > > > This is ma controller > > class UploadController < ApplicationController > def index > puts ''hiiiiiiiiiii'' > render :file => ''app\views\upload\uploadfile.html.erb'' > puts ''hiiiiiiiiiii2'' > end > def uploadFile > puts ''hiiiiiiiiiii3'' > post = DataFile.save(params[:upload]) > render :text => "File has been uploaded successfully" > end > 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org<rubyonrails-talk%2Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> > . > For more options, visit this group at > http://groups.google.com/group/rubyonrails-talk?hl=en. > >-- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Yong Gu wrote:> I think use *render :file => ''uploadfile.html.erb''*, as rails would look > for > the template in your view directory, which is "app/views", > > and if you use render :file => ''controller/uploadfile.html.erb'', it will > look for the template in "app/views/controller/uploadfile.html.erb", or > rails always > > assume you have already put your template in the controller''s according > view > folderwheen i did that i am getting the error like this hiiiiiiiiiii3 SQL (0.5ms) SET client_min_messages TO ''panic'' SQL (0.5ms) SET client_min_messages TO ''notice'' SQL (0.6ms) SET client_encoding TO ''unicode'' Processing UploadController#uploadFile (for 127.0.0.1 at 2010-03-29 11:47:28) [POST] Parameters: {"commit"=>"Upload", "authenticity_token"=>"g1vUQZ7QAh7FjfusjbJuh7EBO4UVVFInaYsxzCMK91I=", "date_file"=>{"upload"=>#<File:/tmp/RackMultipart.3648.0>}} NoMethodError (You have a nil object when you didn''t expect it! You might have expected an instance of ActiveRecord::Base. The error occurred while evaluating nil.[]): -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Did you add uploadFile to route.rb? And i think you''d better follow rails'' convention, instead of writing code as like using some other frameworks On Mon, Mar 29, 2010 at 2:26 PM, Tony Augustine <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org>wrote:> Yong Gu wrote: > > I think use *render :file => ''uploadfile.html.erb''*, as rails would look > > for > > the template in your view directory, which is "app/views", > > > > and if you use render :file => ''controller/uploadfile.html.erb'', it will > > look for the template in "app/views/controller/uploadfile.html.erb", or > > rails always > > > > assume you have already put your template in the controller''s according > > view > > folder > > wheen i did that i am getting the error like this > > hiiiiiiiiiii3 > SQL (0.5ms) SET client_min_messages TO ''panic'' > SQL (0.5ms) SET client_min_messages TO ''notice'' > SQL (0.6ms) SET client_encoding TO ''unicode'' > > > Processing UploadController#uploadFile (for 127.0.0.1 at 2010-03-29 > 11:47:28) [POST] > Parameters: {"commit"=>"Upload", > "authenticity_token"=>"g1vUQZ7QAh7FjfusjbJuh7EBO4UVVFInaYsxzCMK91I=", > "date_file"=>{"upload"=>#<File:/tmp/RackMultipart.3648.0>}} > > NoMethodError (You have a nil object when you didn''t expect it! > You might have expected an instance of ActiveRecord::Base. > The error occurred while evaluating nil.[]): > -- > 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org<rubyonrails-talk%2Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> > . > For more options, visit this group at > http://groups.google.com/group/rubyonrails-talk?hl=en. > >-- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
hi yong i got the same proble and solved it , you can use in form tag uploadfile instead of uploadFile and in render file : use #"{root_url}/app/view/--path" hope you will solve it .. thanks rahul On Mar 28, 10:32 pm, Yong Gu <zerogy...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Did you add uploadFile to route.rb? > > And i think you''d better follow rails'' convention, instead of writing code > as like using some other frameworks > > On Mon, Mar 29, 2010 at 2:26 PM, Tony Augustine <li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org>wrote: > > > > > Yong Gu wrote: > > > I think use *render :file => ''uploadfile.html.erb''*, as rails would look > > > for > > > the template in your view directory, which is "app/views", > > > > and if you use render :file => ''controller/uploadfile.html.erb'', it will > > > look for the template in "app/views/controller/uploadfile.html.erb", or > > > rails always > > > > assume you have already put your template in the controller''s according > > > view > > > folder > > > wheen i did that i am getting the error like this > > > hiiiiiiiiiii3 > > SQL (0.5ms) SET client_min_messages TO ''panic'' > > SQL (0.5ms) SET client_min_messages TO ''notice'' > > SQL (0.6ms) SET client_encoding TO ''unicode'' > > > Processing UploadController#uploadFile (for 127.0.0.1 at 2010-03-29 > > 11:47:28) [POST] > > Parameters: {"commit"=>"Upload", > > "authenticity_token"=>"g1vUQZ7QAh7FjfusjbJuh7EBO4UVVFInaYsxzCMK91I=", > > "date_file"=>{"upload"=>#<File:/tmp/RackMultipart.3648.0>}} > > > NoMethodError (You have a nil object when you didn''t expect it! > > You might have expected an instance of ActiveRecord::Base. > > The error occurred while evaluating nil.[]): > > -- > > Posted viahttp://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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > > To unsubscribe from this group, send email to > > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org<rubyonrails-talk%2Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> > > . > > For more options, visit this group at > >http://groups.google.com/group/rubyonrails-talk?hl=en.- Hide quoted text - > > - Show quoted text --- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.