轨道3:Ajax的更新视图部分 [英] Rails 3: Ajax-updating a view with a partial

查看:145
本文介绍了轨道3:Ajax的更新视图部分的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在做什么毛病下面的Ajax请求......?

what am I doing wrong with the following Ajax request...?

<%= link_to 'Business Analysis', it_business_analysis_path, :remote => true %>

的路线:

match 'it/business_analysis' => 'informationtechnology#business_analysis', :as => :it_business_analysis

控制器:

class InformationtechnologyController < ApplicationController  
  def business_analysis

    render :update do |page|
      page.replace_html 'page_content', :partial => 'business_analysis'
    end

  end
end

的看法:

<div id="page_content">
</div>

的部分被称为:

_business_analysis.html.erb

的错误:

Action Controller: Exception caught

<h1>Template is missing</h1>
<p>Missing template informationtechnology/update, application/update with {:formats=&gt;[:js, &quot;application/ecmascript&quot;, &quot;application/x-ecmascript&quot;, :html, :text, :js, :css, :ics, :csv, :xml, :rss, :atom, :yaml, :multipart_form, :url_encoded_form, :json], :handlers=&gt;[:builder, :coffee, :erb], :locale=&gt;[:en, :en]}. Searched in: * &quot;/home/<user_name>/Websites/<project_name>/app/views&quot;

看来Rails是寻找一个名为更新的看法 - 为什么?如何解决这个问题

It seems Rails is looking for a view called "update" - why and how do I fix this?

非常感谢! 汤姆

推荐答案

好了,任何人具有类似isssue,我找到了解决办法:

Ok, for anybody having a similar isssue, I found the solution:

的问题是,在Rails3,原型置换与jQuery。为此以下code是不再有效:

The problem is that, in Rails3, Prototype was replaced with jQuery. Therefor the following code is no longer valid:

render :update do |page|
  page.replace_html 'page_content', :partial => 'business_analysis'
end

下面的2个链接会解释如何处理jQuery的细节:

The following 2 links will explain the details on how to deal with jQuery:

轨道3:简单AJAXy页面更新

http://railscasts.com/episodes/205-unobtrusive-javascript

汤姆

这篇关于轨道3:Ajax的更新视图部分的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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