2013-06-24 48 views
2

我正在使用rails ajax刪除公司的一個分支。在軌中的#<#<Class:0xbe53d68>:0xcf9cb24>的未定義方法`capture_haml'

的公司帳戶進行簡單的形式是 -

= 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對象的性反應 -

$('#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' 
+2

回溯在這裏會有很大的幫助。如果你不調用'capture_haml',聽起來像你的助手之一,並且在不應該的情況下。 – Matchu

+0

我做了所有的回溯,沒有運氣.. :( – User16119012

+0

我認爲他意味着你應該發佈你得到的'undefined method'結果的回溯。 – aceofspades

回答

1

我用另一種方式解決了這個問題。

我正在渲染區域的主要部分,其中創建了@company帳戶的表單。然後保持_regions.html.haml中的有效/無效分支部分在其上添加條件。

加載頁面時,默認顯示活動分支,並根據發送的請求顯示非活動分支,然後呈現非活動分支部分。

相關問題