dimanche 30 août 2015

Getting only file name as string

i am trying to upload a file in rails

i have created a model with following code

def self.save(upload,id)
    name =  upload[:img].original_filename
    directory = "public/user_db"
    # create the file path
    path = File.join(directory, id)
    # write the file
    File.open(path, "wb") { |f| f.write(upload['img'].read) }
  end
end

my view have following field.

<div class="field">
  <input type="file" name="img" id="img" placeholder="upload your DP" />
</div>

my controller is calling save function as following :

post = DataFile.save(params,@fbuser.id)

But a am getting this errorenter image description here

Aucun commentaire:

Enregistrer un commentaire