小编典典

Rails 3:Ajax更新带有局部视图的视图

ajax

以下Ajax请求在做什么错…?

链接/通话:

<%= 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正在寻找一个名为“更新”的视图-为什么以及如何解决此问题?

非常感谢!汤姆


阅读 245

收藏
2020-07-26

共1个答案

小编典典

好的,对于任何有类似问题的人,我都找到了解决方案:

问题在于,在Rails3中,Prototype被jQuery取代。因此,以下代码不再有效:

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

以下2个链接将说明有关如何处理jQuery的详细信息:

Rails
3:简单的AJAXy页面更新?

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

汤姆

2020-07-26