0

Im working with a GEM call best_in_place : https://github.com/bernat/best_in_place

Creation of new todo items are done with:

<%= best_in_place @user, :name, :type => :input, :nil => "Click me to add content!" %>

respond_to :html, :json, :js

def todo_item_fast_create
    @todo_list = TodoList.find(params[:id])
    @todo_item = @todo_list.todo_items.new(params[:todo_item])
    @todo_item.save
    respond_with @todo_item
end

The response code is JSON, but I would like to call a JS template so I can manipulate the DOM, is that possible?

4

1 回答 1

0

您将必须创建一个文件名如下的视图模板:todo_item_fast_create.js.erb该文件将在调用该操作时提供。您可能必须添加:remote => true到调用此操作的按钮或链接。

这是我的 JS 文件之一:new.js.erb(在我安排新导出时调用)。

$("#export_modal").html("<%= escape_javascript(render("new")) %>");
<!-- trigger the modal to open -->
$("#export_modal").modal('show');

$("#popover1").popover();

该调用escape_javascript(render("new"))将部分呈现到 js 响应中,我让 js 处理更新 DOM。

于 2013-01-17T17:30:23.943 回答