Rails form_tag提交数据而无需重新加载整个页面

时间:2017-02-23 13:29:30

标签: javascript ruby-on-rails-4 page-refresh

我有一个名为搜索数据库渲染数据的模型,使用索引方法我可以访问3个模型中的数据,并将其显示在索引页面上。 我在索引页面中使用了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 =&gt;在form_tag中为true,我不知道在哪里以及如何为此调用ajax? 我正在使用&#39;&lt;%= escape_javascript @ center_lat.to_json%&gt;&#39;来搜索表中的数据并获取更新的数据。在index.html.erb文件中

任何帮助都会很明显。

1 个答案:

答案 0 :(得分:0)

您正在使用:method => "get"来制作获取请求,页面将始终重新加载,请尝试将其删除并尝试查看是否有效。

此外,您的控制器需要能够应答JS调用,让您在控制器上调用的操作具有类似的功能

respond_to do |f|
f.html { redirect_to tasks_url }
f.js

相关问题