How can i upload a file in a directory using ruby mine? -


this modal file data_file.rb

    class datafile < activerecord::base   # attr_accessible :title, :body   def self.save(upload)     name =  upload['datafile'].original_filename     directory = "public/data"     # create file path     path = file.join(directory, name)     # write file     file.open(path, "wb") { |f| f.write(upload['datafile'].read) }   end end 

this controller file

class uploadcontroller < applicationcontroller   def index     render :file => 'app\views\upload\uploadfile.html.erb'   end   def uploadfile     post = datafile.save(params[:upload])     render :text => "file has been uploaded successfully"   end end 

and view file

 <h1>file upload</h1> <%= form_tag :action => 'uploadfile'  %> <p><label for="upload_file">select file</label> :   <%= file_field 'upload', 'datafile' %></p> <%= submit_tag "upload" %> <%= end %> 

whenever try access view file using syntax http://127.0.0.1:3000/upload/index.....i following error

showing c:/users/pratik/rubymineprojects/upload/app/views/upload/uploadfile.html.erb line #6 raised:

c:/users/pratik/rubymineprojects/upload/app/views/upload/uploadfile.html.erb:6: syntax error, unexpected keyword_end ');@output_buffer.append= ( end );@output_buffer.to_s                                ^ c:/users/pratik/rubymineprojects/upload/app/views/upload/uploadfile.html.erb:7: syntax error, unexpected keyword_ensure, expecting ')' c:/users/pratik/rubymineprojects/upload/app/views/upload/uploadfile.html.erb:9: syntax error, unexpected keyword_end, expecting ')' extracted source (around line #6):  3: <p><label for="upload_file">select file</label> : 4:   <%= file_field 'upload', 'datafile' %></p> 5: <%= submit_tag "upload" %> 6: <%= end %> 

this project sample project on tutorialpoints.com. when try fails. using ruby mine ide. can please guide me?? of great help.

the last line of view file: <%= end %>

you need remove = sign

answer second question

<%= form_tag :action => 'uploadfile' %> faulty

  • open console
  • cd in application directory: cd \users\pratik\rubymineprojects\upload
  • type rake routes
  • you see among lot of lines, should resemble (your output may different) :

    upload    /upload(.:format)    upload#index        post   /upload(.:format)    upload#create 
  • on left side of "get", note name appear (in example 'upload' may different in output)

  • then use name in view form_tag appening _path it, result should have this: <%= form_tag upload_path %>

Comments

Popular posts from this blog

javascript - DIV "hiding" when changing dropdown value -

Does Firefox offer AppleScript support to get URL of windows? -

android - How to install packaged app on Firefox for mobile? -