如何在rails 3.2中通过ajax更新多个部分在这里我做了我的ajax请求
$.ajax({
url: "/home/create_entry",
type: "POST",
data: params,
cache: false,
success: function(data) {
$('#'+did).html(data);
// $("#results").html('<%#=j render(:partial => 'explorer', :locals => {:entries => @entries, :entry_count=> @entry_count}) %>');
}
});
在控制器中写入
def create_entry
if request.xhr?
@entry = Entry.new
@entry.title = params[:title]
respond_to do |format|
if @entry.save
flash[:notice] = "Entry created successfully"
@entry = Entry.last
@entries = Entry.where(:user_id => current_user.id).order(sort_column + ' ' + sort_direction)
@entry_count = @entries.count
format.js
end
end
end
在 create_entry.js.erb
<%= render :partial => 'edit_entry_form', :locals => {:entry => @entry}%>
<%= render :partial => 'explorer', :locals => {:entries => @entries}%>
现在我可以获取这两个数据,我如何在 ajax 请求成功后更新这两个部分?
提前致谢。