【问题标题】:Selecting second entry in rails console?在rails控制台中选择第二个条目?
【发布时间】:2013-08-20 03:22:08
【问题描述】:

我需要选择 User 模型中的第二个条目。

User.second 不起作用,User.2User.two 也不起作用。

我正在尝试将 u 设置为第二个用户条目 (u = User.2)

【问题讨论】:

    标签: ruby-on-rails rails-console


    【解决方案1】:

    以下应该有效:

    User.all.second
    User.offset(1).first
    
    # Assuming you are using incremental keys and have users with ID's 1 and 2:
    User.find(2)
    

    【讨论】:

      猜你喜欢
      • 2016-05-08
      • 2012-07-13
      • 2011-04-11
      • 1970-01-01
      • 2020-04-27
      • 1970-01-01
      • 1970-01-01
      • 2019-04-05
      • 2015-10-15
      相关资源
      最近更新 更多