我正在使用 rails ajax
删除一家公司的分支机构。
公司帐户的简单表格是 -
= simple_form_for @company_account, :remote => true,
:url => company_account_path,
:method => :put do |f|
我正在使用此表单创建、更新和删除区域和区域分支。
%div{ :id => 'branches_' + r.id.to_s}= render 'branches',f: f, r: region, company_account: @company_account
公司、地区、分支机构之间的关系是:
company has_many: regions
region belong_to: company
regions has_many: branches
branches belongs_to: regions
在这个表单中,我有一个部分用于显示区域和分支机构,它使用公司帐户 f
的表单对象。所有这些都工作正常。我能够创建新的区域分支。现在我正在尝试使用 ajax
删除分支。
当此调用转到 Controller 时,我正在为公司帐户创建一个表单对象以呈现部分类似 - 在我的 Controller 中
@f = view_context.simple_form_for @company_account, :remote => true,
:url => company_account_path,
:method => :put do |f|
render_to_string(:partial => 'company_accounts/branches', :locals => {f: f, r: @region, company_account: @company_account }).html_safe
end
并使用 javascript 作为响应传递此 @f 对象 -
$('#branches_' + <%= @region.id%>).html('<%= escape_javascript @f %>');
$('#branches_' + <%= @region.id%>).show();
但不幸的是,我得到了错误的回应 -
undefined method `capture_haml' for #<#<Class:0xbe53d68>:0xcf9cb24>
不知道我错过了什么。任何人都可以帮忙吗??
提前致谢。
更新:
这是回溯:
ActionView::Template::Error (undefined method `capture_haml' for #<#<Class:0xb9db2a4>:0xc953560>):
1: #inactive_branches
2: = f.simple_fields_for :regions, r do |reg|
3: %table.preferenceDetails
4: %tr
5: %td
app/views/company_accounts/_inactive_branches.html.haml:2:in `_app_views_company_accounts__inactive_branches_html_haml___356774371_104988750'
app/controllers/company_accounts_controller.rb:129:in `block in branches'
app/controllers/company_accounts_controller.rb:122:in `branches'
最佳答案
我用另一种方式解决了这个问题。
我正在渲染区域的主要部分,在其中创建了@company 帐户的表单。然后在 _regions.html.haml
中保留事件/非事件分支部分并在其上添加条件。
加载页面时,它默认显示事件分支,并根据发送的请求显示非事件分支,然后呈现部分非事件分支。
关于ruby - #<#<Class :0xbe53d68>:0xcf9cb24> in rails 的未定义方法 `capture_haml',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17271412/