0

I'm using Rails version 3.0.9 and jquery. The problem is that when you click on the link, the div is not updated. There are two actions: "show" and "time". Initial position - show. Controller code was (ajax_controller.rb):

class AjaxController < ApplicationController
  respond_to :html, :js

  def show  
  end

  def time
  end
end

By clicking on the link in the div should be loaded time.

Next code (show.html.erb):

<h1>Ajax show</h1>
Click this link to show the current 
<%= link_to "time", :url=>{:action => "time"}, :remote => true%>.<br/>
<div id='time_div'>
</div>

Also, there are files time.html.erb and time.js.erb. Follow code (time.js.erb):

$('#time_div').html('<%= escape_javascript(render :text => "The current time is #{Time.now.to_s}") %>');

But nothing happens. jquery connected. In what may be the problem?

OLMER
  • 117
  • 1
  • 1
  • 8

2 Answers2

1

You can have issues with routes. Do you have something like this in your routes.rb?

RAILS_ROOT/config/routes.rb

get '/time', :to => 'ajax_controller#time', :as => :ajax_time

and then you should call the url with rails helper like this

<%= link_to "time", ajax_time_path, :remote => true %>
Suborx
  • 3,647
  • 2
  • 19
  • 30
0

You can look at your log to see if time.js.erb is indeed rendered. It is possible that the HTML version is rendered instead. If that's the case, remove the HTML version.

Yosep Kim
  • 2,931
  • 22
  • 23