TomDogg
TomDogg

Reputation: 3940

Rails 3: Ajax-updating a view with a partial

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

Upvotes: 2

Views: 9737

Answers (1)

TomDogg
TomDogg

Reputation: 3940

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

Upvotes: 1

Related Questions