这是我的简单 ajax 代码。
发出了请求,我得到了响应,但我的视图没有用新数据呈现。我得到一个带有新 html 的新页面,我要求渲染它而不是在当前页面中渲染。
控制器 -
def list
@users = User.find(:all)
end
def show
respond_to do |format|
format.html { render :partial => "ajaxshow" }
format.js
end
end
看法 -
<% @users.each do |c| %>
<%= link_to c.user_id, {:action => :show, :user_id => c.user_id, :remote => true } %>
<% end %>
部分的 -
# cat _ajaxshow.html.erb
<div align="left" id="user_ajax">
<table width="1000px">
<tr><th>User ID</th><th>First</th><th>Last</th><th>ID</th><th>Email</th></tr>
</table>
日志 -
Started GET "/users/show?remote=true&user_id=someuser" for 10.10.10.10 at 2012-04-17 04:01:09 -0400
Processing by UsersController#show as HTML
Parameters: {"remote"=>"true", "user_id"=>"someuser"}
Rendered users/_ajaxshow.html.erb (0.3ms)
Completed 200 OK in 2ms (Views: 1.3ms | ActiveRecord: 0.0ms)