0
csv 파일에서 레일 3에 자동 완성을 수행 할 방법이 있는지 알고 싶습니다. 나는 컨트롤러와 함께 HTML 부분 (나는 그것에 대해 모르겠다) 렌더링을하려고 해요. 코드를 아래에 게시. 내가 레일에 새로운 해요, 당신의 도움이 많이레일 3 CSV 파일에서 jquery 자동 완성
class CsvreaderController < ApplicationController
def search_csv
unless params[:search_no].nil?
@winner_attrs = nil
@search_no = params[:search_no]
@file_path = params[:file_path]
File.open(@file_path, "r") do |infile|
p "file opened in read mode"
while (line = infile.gets)
attrs = line.split("\t")
if attrs[0].to_i.equal? @search_no.to_i
p "match found"
p @winner_attrs = attrs
respond_with do |format|
format.html do
if request.xhr?
render :partial => "search_csv",
:locals => { :result => @winner_attrs },
:layout => false,
:status => :created
else
redirect_to "search_csv"
end
end
end
end
end
end
end
end
end
보기 파일을 감사합니다 :
<script>
$('#csv_form').bind('ajax:success', function(evt, data, status, xhr) {
$('#result').html(xhr.responseText);
});
</script>
<%= form_tag({ :action => 'search_csv' },
:remote => 'true',
:id => 'csv_form'
) do
%>
<%= text_field_tag 'search_no', nil, :class => 'textbox' %>
<%= hidden_field_tag 'file_path', 'public/data/final_draw_till_10_Dec.csv' %>
<%= submit_tag "Submit", :name => 'button', :class =>'button' %>
<% end %>
<div id="result"></div>