Rails 3: Ajax-updating a view with a partial

流过昼夜 提交于 2019-12-01 08:10:48

问题


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

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?

Thanks a lot! Tom


回答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:

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:

Rails 3: Simple AJAXy Page updates?

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

Tom



来源:https://stackoverflow.com/questions/7772854/rails-3-ajax-updating-a-view-with-a-partial

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!