【问题标题】:NoMethodError undefined method `link_to_function'NoMethodError 未定义方法 `link_to_function'
【发布时间】:2014-12-01 22:36:49
【问题描述】:

我在我的应用程序中添加了 ActiveAdmin,更新了一些 gem,现在我在查看用户显示页面时收到了 undefined method `link_to_function'。我有 will_paginate gem,我添加了一个初始化程序,所以没有冲突。

kaminari.rb:

Kaminari.configure do |config|
  config.page_method_name = :per_page_kaminari
end

错误指向来自 /app/helpers/will_paginate_helper.rb 的行:

  @template.link_to_function(text.to_s.html_safe, ajax_call, attributes)

【问题讨论】:

  • 两个分页宝石在一起??
  • link_to_function 方法在 Rails 4.1.x 中已弃用。

标签: ruby-on-rails activeadmin will-paginate


【解决方案1】:

添加一个辅助方法,它将解决您的问题。

link_to_function_helper.rb:

module LinkToFunctionHelper
  def link_to_function(name, *args, &block)
     html_options = args.extract_options!.symbolize_keys

     function = block_given? ? update_page(&block) : args[0] || ''
     onclick = "#{"#{html_options[:onclick]}; " if html_options[:onclick]}#{function}; return false;"
     href = html_options[:href] || '#'

     content_tag(:a, name, html_options.merge(:href => href, :onclick => onclick))
  end
end

【讨论】:

    猜你喜欢
    • 2013-04-24
    • 2015-05-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-06-12
    • 2013-11-14
    • 2021-07-07
    • 2017-11-13
    相关资源
    最近更新 更多