How to parse a downloaded txt file in Rails3

I have a form in which there is a file,

<%form_tag '/dboss/newsbsresult' , :remote=>true do %>
    <input type="file" id="examsendbutton" name="txtsbs"/><br/>
    <input type="submit" value="Gonder">
<%end%>

Here I want the user to select a txt file that I am trying to parse and use on the server, but I can not catch the downloaded file with this code,

def newsbsresult
        @u = params[:txtsbs] #Or params[:txtsbs].to_s
        p @u
end

What is the true way to achieve this?

+3
source share
3 answers

AJAX - - . , JavaScript ( HTML 5). AJAX (, file-uploader uploadify ), Rails , :remote => true - - /, .

:remote => true :multipart => true.


:

+2

:multipart => true form_tag

<% form_tag '/dboss/newsbsresult' , :remote=>true, :multipart => true do %>
0

Based on your question, if I understand that this is correct. You want to read data from a download file. I managed to run a similar thing, which should show the loaded text in a different text area of ​​my Rails application.

Here is what I did.

View

  1 <%= form_tag('/dboss/newsbsresult' , :multipart => true) do %>  
  2   <input type="file" id="examsendbutton" name="txtsbs"/><br/>
  3   <input type="submit" value="Gonder">
  4 <% end %>

controller

  1   def index
  2     if (params[:txtsbs].present?)
  3       @upload_text = params[:txtsbs].read
  4       render :text => @upload_text
  5    end
  6   end

Route

  match 'dboss/newsbsresult' => 'user#index'
0
source

Source: https://habr.com/ru/post/1793290/


All Articles