• 我也遇到这个问题,只要浏览器连上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)