【问题标题】:undefined method `link_to_remote' in MiniTest for application_helper testMiniTest 中用于 application_helper 测试的未定义方法“link_to_remote”
【发布时间】:2015-01-22 10:38:25
【问题描述】:

在将应用程序从 Rails 2.3.17 迁移到 3.2.21. 时。在使用 MiniTest 进行测试时,我们遇到了 Rails 旧表单助手 link_to_remote 的问题。

在旧版本的 Rails 中,我们使用了 link_to_remote 表单助手,它在 Rails 3 中被删除。为了提供支持,我们在我们的应用程序中添加了 prototype_legacy_helper 插件,它在UI 但测试失败并抛出如下错误:

NoMethodError: undefined method `link_to_remote' for #<ApplicationHelperTest:0xc800dd4>

这是我们在 ApplicationHelper 中的代码

def reservation_menu_command_link(command, *args)
  ...
  command_link = link_to_remote(anchor_text,options = {}, {:class => style_class})
  ...
end

这是我们的 application_helper 测试用例

def test_reservation_menu_command_link
  options = { :lodging_view => lv}
  assert_equal(%q{xyz}, reservation_menu_command_link(:cancel_all_possible, options))
end

所以你可以看到我们有一个方法 reservation_menu_command_link,我们在 UI 中使用了它,它工作正常,但测试这个定义失败。

谁能帮助我摆脱插件的这种行为?

【问题讨论】:

  • 这个问题你解决了吗?你能添加你Gemfile的信息吗?
  • 是的,这个问题已经解决了。我不知道确切的解决方案。我正在使用 gem 'prototype_legacy_helper', '0.0.0', :git => 'git://github.com/rails/prototype_legacy_helper.git` 作为 Rails legacy helpers 。如果我得到任何适当的解决方案,我会将其发布为答案。

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


【解决方案1】:

link_to_remote 在 Rails 2 和 3 之间被弃用,这些天的正确用法是

link_to 'Foo', { action: 'create' }, remote: true。希望对您有所帮助

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多