渲染的部分在使用jquery轨 [英] Render a partial in rails using jquery

查看:89
本文介绍了渲染的部分在使用jquery轨的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图安装加载部分变成一个div元素,当用户点击链接在我的主页的导航栏。我已经遵循了这个职位的步骤,并修改它们,因为我认为我需要: <一href="http://stackoverflow.com/questions/4766383/rails-3-link-to-to-call-partial-using-jquery-ajax">Rails 3 - 的link_to使用调用部分jQuery的AJAX

I am trying to setup a navigation bar on my home page that loads a partial into a div element when the user clicks on the links. I have followed the steps in this post and modified them as I thought I needed: Rails 3 - link_to to call partial using jquery ajax

我的code:

的意见/页/ home.html.erb:

<%= link_to "Files", :action => 'load_upload_partial', :remote => true %>

。 。

<div id="main_frame"></div>

pages_controller:

def load_upload_partial  
    respond_to do | format |  
      format.js {render :layout => false}  
    end
end

/views/uploads/load_upload_partial.js.erb:

$("#main_frame").html( "<%= escape_javascript( render( :partial => "/upload/upload_form" ) %>" );

在这个例子中的部分只是一种形式。当我点击链接,我得到这个空白页面的地址栏: 的http://本地主机:3000 / load_upload_partial远程=真

The partial in this example is just a form. When I click on the link I get a blank page with this is the address bar: http://localhost:3000/load_upload_partial?remote=true

这让我觉得,链接不会触发一个Ajax GET请求(如果这是正确的术语)。如果是这样的话有什么我需要被添加到我的application.js文件?我也跟着在轨道和jQuery的railscast#136,但无法找出其中的application.js code位应用到我的情况。 任何想法是多少AP preciated。谢谢。汤姆

This makes me think that link is not triggering an ajax GET request (if that's the correct terminology). If that is the case is there anything I need to be adding to my application.js file? I followed the railscast #136 on rails and jquery but couldn't figure out which bits of the application.js code applied to my case. Any thoughts are much appreciated. Thanks. Tom

推荐答案

我现在倾向于避免使用RJS就像你打算。我preFER包含把手工具创建的js模板。

I now tend to avoid using RJS like you're intending to. I prefer creating js templates with tools like handlebars.

我只使用Ajax来获得原始数据,然后重新创建部分客户端。这是多服务器负载和数据传输的更好。

I only use ajax to get raw data and then recreate the partial client side. It's much better for server load and data transfer.

这篇关于渲染的部分在使用jquery轨的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆