3

を使用して会社の支店を削除する作業を行ってい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'
4

1 に答える 1

2

この問題を別の方法で修正しました。

@company アカウントのフォームが作成されるリージョンの主要部分をレンダリングしています。_regions.html.haml次に、条件を追加する際に、両方のアクティブ/非アクティブ ブランチ パーシャルを保持しました。

ページがロードされると、デフォルトでアクティブなブランチが表示され、非アクティブなブランチを表示するために送信されたリクエストに基づいて、非アクティブなブランチの部分がレンダリングされます。

于 2013-07-02T11:20:55.573 に答える