Rails 3: ajax更新视图,带有部分内容。

时间:2022-10-08 16:28:01

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

下面的Ajax请求我做错了什么?

The link/call:

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

The route:

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

The controller:

class InformationtechnologyController < ApplicationController  
  def business_analysis

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

  end
end

The view:

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

The partial is called:

_business_analysis.html.erb

The ERROR:

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;

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

看起来Rails正在寻找一种名为“更新”的视图——为什么,我该如何修复它?

Thanks a lot! Tom

谢谢!汤姆

1 个解决方案

#1


1  

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

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

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

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

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

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

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

Rails 3: Simple AJAXy Page updates?

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

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

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

Tom

汤姆

#1


1  

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

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

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

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

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

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

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

Rails 3: Simple AJAXy Page updates?

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

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

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

Tom

汤姆