I want to upload file in form but do not want its field inside a model. so using the file_filed_tag
at view:
<%= form_tag services_datainterchange_path, method: :post, remote: true do %>
<div class="row">
<div class="col-sm-3 col-md-3">
<div class="form-group">
<%= label_tag :file %>
<%= file_field_tag :file, required: true, class: "form-control", id: "upload_file" %>
</div>
</div>
<div class="col-sm-2 col-md-2">
<div class="form-group">
<%= label_tag :name %>
<%= text_field_tag :name, nil, required: true, class: "form-control", id: "upload_file_name" %>
</div>
</div>
<div class="col-sm-2 col-md-2">
<div class="form-group">
<%= label_tag :source_type %>
<%= select_tag :source_type, options_for_select(ApplicationRecord::SOURCE_TYPE), class: "form-control" %>
</div>
</div>
<div class="col-sm-2 col-md-2">
<div class="form-group">
<%= label_tag :final_type %>
<%= select_tag :final_type, options_for_select(ApplicationRecord::FINAL_TYPE), class: "form-control" %>
</div>
</div>
<div class="col-sm-2 col-md-2">
<div class="form-group">
<%= submit_tag "Submit", class: "btn btn-primary" %>
</div>
</div>
</div>
<% end %>
At controller:
directory = "public/job_files"
Find.find( directory ) do |fpath|
if FileTest.file?( fpath )
fpath.clone(params[:file])
end
end
But file not upload the parameter do get submit of form. Thanks
Aucun commentaire:
Enregistrer un commentaire