我有模型稱爲搜索從數據庫渲染數據,使用索引方法我正在訪問3個模型的數據,並將其顯示在索引頁上。 我使用的form_tag索引頁面本身,Rails的form_tag提交數據,而無需重新加載整個頁面
<%= form_tag(search_path, :method => "get", :remote => true, id: "search-form") do %>
<label for="Longitude ">Lon</label>
<%= text_field_tag :lng, params[:lng], :id => "longitude", placeholder: "Longitude" %>
<label for="Latitude ">Lat</label>
<%= text_field_tag :lat, params[:lat], :id => "latitude", placeholder: "Latitude" %>
<button class="btn waves-effect waves-light" >Process</button>
<% end %>
我還沒有建立這方面的任何局部視圖。
我添加了:remote => true在form_tag中,我不知道在哪裏以及如何爲此調用ajax? 我正在從表中搜索數據並使用'<%= escape_javascript @ center_lat.to_json%>獲取更新的數據';在index.html.erb文件中
任何幫助將是可觀的。
我已經加入到format.js我的控制器索引操作,創建.js,erb視圖,但在該視圖中如何呈現索引操作? – Pbms
看看這裏:http://guides.rubyonrails.org/working_with_javascript_in_rails.html#server-side-concerns,你需要使用一些JavaScript來呈現你的結果,而無需重新加載頁面。 – Victor