0

我在我的 rails3.1 应用程序中使用数据表并且它可以工作,直到我尝试为返回的字段之一(倒数第二个字段)使用路由路径。不管我使用什么有效的路由路径,我都会收到错误NoMethodError (undefined method 'active_toggle_user_path' for #<UsersDatatable:0x007f9d16cf0188>):

有什么建议么?

def data
  users.map do |user|
    [
      link_to(user.last_name, user),
      user.first_name,
      user.username,
      user.email,
      user.security_role,
      user.last_login_at,
      user.active == true ? 'Disable' : link_to('Enable', active_toggle_user_path(user, :toggle => true), { :confirm => 'Are you sure you want to ENABLE this User?', :class => "enable" }),
      'Delete User?'
    ]
  end
end
4

1 回答 1

3

使用解决Rails.application.routes

class UsersDatatable
  delegate :url_helpers, to: 'Rails.application.routes'

  def data
    users.map do |user|
      [
        link_to(user.last_name, user),
        user.first_name,
        user.username,
        user.email,
        user.security_role,
        user.last_login_at,
        user.active == true ? 'Disable' : link_to('Enable', url_helpers.active_toggle_user_path(user, :toggle => true), { :confirm => 'Are you sure you want to ENABLE this User?', :class => "enable" }),
        'Delete User?'
      ]
    end
  end
end
于 2012-09-06T22:25:04.687 回答