AJAX表单和Rails在js模板上呈现?

时间:2014-04-08 14:43:34

标签: javascript ruby-on-rails ruby ajax

我一直得到这个丢失的模板错误,我不知道如何解决。我有一个远程link_to,它创建对新操作的调用,然后呈现包含渲染到html表单的new.js.erb。我希望ajax调用进入,路由到new.js.erb,以便它可以将常规new(包括表单)添加到$('#form_account_contact')中。我也附上了目录结构。

new.js.erb

$('#form_account_contact').html('<%= escape_javascript render("new") %>');

错误:

ActionView::Template::Error (Missing partial tools/api_loaders/account_contact/new, application/new with {:locale=>[:en], :formats=>[:js, :html], :handlers=>[:erb, :builder, :raw, :ruby, :jbuilder, :coffee]}. Searched in:
  * "/Users/tmedford/XXXX/XXXX/app/views"
  * "/Users/tmedford/.rvm/gems/ruby-2.0.0-p247/bundler/gems/mercury-1cc637b0bcce/app/views"
  * "/Users/tmedford/.rvm/gems/ruby-2.0.0-p247/gems/devise_security_extension-0.8.0/app/views"
  * "/Users/tmedford/.rvm/gems/ruby-2.0.0-p247/gems/devise-3.2.3/app/views"
):
    1: $('#form_account_contact').html('<%= escape_javascript render("new") %>');
  app/views/tools/api_loaders/account_contact/new.js.erb:1:in `_app_views_tools_api_loaders_account_contact_new_js_erb___3020976815342708085_70105536181780'
  app/controllers/application_controller.rb:94:in `set_time_zone'

view directory

Controller Directory and new call

1 个答案:

答案 0 :(得分:1)

更新

$('#form_account_contact').html('<%= escape_javascript render("new") %>');

$('#form_account_contact').html('<%= escape_javascript render("form") %>');

new.js.erb中,您尝试将form部分渲染。您传递的部分名称不正确,这就是您收到错误的原因,因为没有名称为new的部分名称。