• 我也遇到这个问题,只要浏览器连上 cable,网站就挂起半天打不开。只要把连上 cable 的页面关闭,网站马上就恢复正常了。服务器使用的是 Passenger+Nginx

  • 修改你的cn.ymlcn.rb,然后参照下面的代码:

    _, data = IO.read(__FILE__).split(/^__END__$/, 2)
    
    counter = 10
    YAML.load(ERB.new(data).result(binding))
    
    __END__
    en:
      human:
        <% 1.upto counter do |i|%>
        xx_<%=  i %>: <%= i %>
        <% end %>
    

    进入 Rails console 调试看看结果:

    [1] pry(main)> I18n.t('human')
    => {:xx_1=>1, :xx_2=>2, :xx_3=>3, :xx_4=>4, :xx_5=>5, :xx_6=>6, :xx_7=>7, :xx_8=>8, :xx_9=>9, :xx_10=>10}
    
  • 可以直接 includes(:contests) 或定义一个 scope

    class Problem < ActiveRecord::Base
      has_many :contest_problems
      has_many :contests, through: :contest_problems
      scope :include_contests, ->{ includes(:contests) }
    end
    

    c.problems.include_contests.find(1)