を使用して会社の支店を削除する作業を行ってい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
います。
この呼び出しがコントローラーに送られると、会社のアカウントのフォームオブジェクトを作成して、部分的なものをレンダリングします-コントローラーで
@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オブジェクトをresponceに渡します-
$('#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'