【问题标题】:undefined method `capture_haml' for #<#<Class:0xbe53d68>:0xcf9cb24> in railsrails 中#<#<Class:0xbe53d68>:0xcf9cb24> 的未定义方法“capture_haml”
【发布时间】:2013-06-24 08:49:04
【问题描述】:

我正在使用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对象 -

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

【问题讨论】:

  • 回溯在这里会有很大帮助。如果你不打电话给capture_haml,听起来你的助手之一是,而且在不应该的情况下。
  • 我做了所有的回溯,没有运气..:(
  • 我认为他的意思是您应该发布由您获得的undefined method 产生的回溯。
  • 哇抱歉.. 更新了我的错误日志
  • 我已经通过另一种方式解决了这个问题。但我想看看为什么这会导致这个问题的可能解决方案,如果 cme 遇到同样的问题,这将帮助其他人。所以如果有人回答剩下5天,我还是会接受答案...:)

标签: ruby ruby-on-rails-3 haml


【解决方案1】:

我用另一种方式解决了这个问题。

我正在渲染区域的主要部分,其中创建了@company 帐户的表单。然后将两个活动/非活动分支部分保留在_regions.html.haml 中,并在其上添加条件。

页面加载时默认显示活动分支,并根据发送的显示非活动分支的请求,然后呈现部分非活动分支。

【讨论】:

    猜你喜欢
    • 2020-05-30
    • 1970-01-01
    • 2016-12-11
    • 1970-01-01
    • 2020-01-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-10-12
    相关资源
    最近更新 更多