First of all, I'm a real beginner in RoR, so excuse the simplicity of the question. I am trying to upload a file with POST parameters. The form is basic : A text_field (not related with the file) and a file_field. I am using CarrierWave gem. The idea is to get the choosen file from the user and upload it in a local folder.
I can't manage to upload the file and I don't understand why. Someone has an idea ?
My code :
view/home/index.html.erb
<%= form_for @home, :url => {:action => 'uploadFile'}, :html => {:multipart => true} do |f|%>
<div class="field">
<tr>
<td><%= f.label :campagne, "Nom de la campagne : " %></td>
<td><%= text_field_tag :campagne %></td>
</tr>
</div>
<div class="field">
<tr>
<td><%= f.label :fichier, "Fichier de numéros : " %></td>
<td><%= f.file_field :fichier %></td>
</tr>
</div>
</table>
<p><%= f.submit "Charger le fichier"%></p>
<% end %>
home_controller :
def index
self.new
render :file => 'app\views\home\index.html.erb'
end
def new
@home = Home.new(params[:fichier])
end
def uploadFile
#campagne = params[:campagne]
#chemin = params[:numeros]
#post = DataFile.save(params[:upload])
#render :text => "Nom de la capagne : #{campagne} et Chemin du fichier : #{chemin}"
#post = DataFile.save(params[:upload])
require "carrierwave"
# Stockage du fichier à l'aide de CarrierWave
stockage = FichierUploader.new
stockage.store!(params[:fichier])
render :text => "File has been uploaded successfully " + " Campagne : " + params[:campagne] + " Fichier : " + params[:fichier].to_s
end
routes.rb :
match "home" => "home#index"
match "home/uploadFile" => "home#uploadFile"
resources :home
get 'home/uploadFile'
post 'home/uploadFile'