• ruby-china gem 源的问题 at June 01, 2023

    +1 遇到好几次了,每次都去刷新下 Gem 源

  • *经问题,选什么 ide at January 19, 2020

    A 项目用 RubyMine,B 项目用 Vim,C 项目 RubyMine 和 Vim 混合用。

    RubyMine 的跳转是真的爽。

  • 辛苦了👍

  • 👍

  • Rails 接口如何返回 XML at July 18, 2019

    👍 我咋就没想到呢

  • 内存满了吧

  • Rails has_many 定义问题 at May 29, 2019

    这样?猜的。

    has_many :prevdetail_tmps, :dependent => :destroy
    
    scope :my_order, -> { includes(:prevdetail_tmps).order('prevdetail_tmps.day_from, m_selectlists.sort_no') }
    
  • 1.新增一个 migration,用于 posts 表添加 user_id

    2.新增一个 task,用于更新数据

  • 👍

  • 我的透明创业实验 at May 21, 2019

    羡慕

  • bundle exec sidekiq +1

  • 关于 Ruby 的正则问题 at June 14, 2018
    '16DC203B5R'.scan(/(\d+)([a-zA-Z]+)/)
    => [["16", "DC"], ["203", "B"], ["5", "R"]]
    
  • Really young.

  • 有道理,感觉像是在重新编译所有静态资源。

    项目的静态资源很大,可以用“庞然巨物”来形容~

  • 没错assets:precompile导致的,public 设置了 link_dir,每次编译大约需要 5 分钟,不知有什么好的解决方法?

    目前解决方法是不使用 capistrano 编译,写脚本 ssh 进行编译,大约 20s 左右。

  • images 是表名,单复数根据关联联系决定。

  • Post.includes(:images).find(1).images
    
  • Rails5.0 ~~~,可以兼容到 Rails4 么

  • Capistrano 在执行 bundle install 时服务器 CPU 会爆满,请问这个问题怎么解决?

  • 多谢,搞定了,是文件权限问题,mongodb/这个目录的所有者必须是 mongodb,可以使用这个命令修复:

    sudo chown -R mongodb:mongodb *
    

    权限改成这样:

    drwxr-xr-x 4 mongodb mongodb 4.0K Mar 20 10:55 mongodb
    
  • 日志内容是这样的,没看出来哪里出错了,请指教🙏

    2018-03-20T10:09:21.433+0800 I CONTROL  [main] ***** SERVER RESTARTED *****
    2018-03-20T10:09:21.436+0800 I CONTROL  [initandlisten] MongoDB starting : pid=17726 port=27017 dbpath=/home/mongodb 64-bit host=smart
    2018-03-20T10:09:21.436+0800 I CONTROL  [initandlisten] db version v3.4.13
    2018-03-20T10:09:21.436+0800 I CONTROL  [initandlisten] git version: fbdef2ccc53e0fcc9afb570063633d992b2aae42
    2018-03-20T10:09:21.436+0800 I CONTROL  [initandlisten] OpenSSL version: OpenSSL 1.0.2g  1 Mar 2016
    2018-03-20T10:09:21.436+0800 I CONTROL  [initandlisten] allocator: tcmalloc
    2018-03-20T10:09:21.436+0800 I CONTROL  [initandlisten] modules: none
    2018-03-20T10:09:21.436+0800 I CONTROL  [initandlisten] build environment:
    2018-03-20T10:09:21.436+0800 I CONTROL  [initandlisten]     distmod: ubuntu1604
    2018-03-20T10:09:21.436+0800 I CONTROL  [initandlisten]     distarch: x86_64
    2018-03-20T10:09:21.436+0800 I CONTROL  [initandlisten]     target_arch: x86_64
    2018-03-20T10:09:21.436+0800 I CONTROL  [initandlisten] options: { config: "/etc/mongod.conf", net: { bindIp: "127.0.0.1", port: 27017 }, storage: { dbPath: "/home/mongodb", journal: { enabled: true } }, systemLog: { destination: "file", logAppend: true, path: "/var/log/mongodb/mongod.log" } }
    2018-03-20T10:09:21.460+0800 I -        [initandlisten] Detected data files in /home/sunyudong/database/mongodb created by the 'wiredTiger' storage engine, so setting the active storage engine to 'wiredTiger'.
    2018-03-20T10:09:21.460+0800 I STORAGE  [initandlisten]
    2018-03-20T10:09:21.460+0800 I STORAGE  [initandlisten] ** WARNING: Using the XFS filesystem is strongly recommended with the WiredTiger storage engine
    2018-03-20T10:09:21.460+0800 I STORAGE  [initandlisten] **          See http://dochub.mongodb.org/core/prodnotes-filesystem
    2018-03-20T10:09:21.460+0800 I STORAGE  [initandlisten] wiredtiger_open config: create,cache_size=3406M,session_max=20000,eviction=(threads_min=4,threads_max=4),config_base=false,statistics=(fast),log=(enabled=true,archive=true,path=journal,compressor=snappy),file_manager=(close_idle_time=100000),checkpoint=(wait=60,log_size=2GB),statistics_log=(wait=0),verbose=(recovery_progress),
    2018-03-20T10:09:21.674+0800 I STORAGE  [initandlisten] WiredTiger message [1521511761:674256][17726:0x7f4c98877d00], txn-recover: Main recovery loop: starting at 11/5632
    2018-03-20T10:09:21.760+0800 I STORAGE  [initandlisten] WiredTiger message [1521511761:760006][17726:0x7f4c98877d00], txn-recover: Recovering log 11 through 12
    2018-03-20T10:09:21.857+0800 I STORAGE  [initandlisten] WiredTiger message [1521511761:857612][17726:0x7f4c98877d00], txn-recover: Recovering log 12 through 12
    2018-03-20T10:09:22.359+0800 I CONTROL  [initandlisten] 
    2018-03-20T10:09:22.360+0800 I CONTROL  [initandlisten] ** WARNING: Access control is not enabled for the database.
    2018-03-20T10:09:22.360+0800 I CONTROL  [initandlisten] **          Read and write access to data and configuration is unrestricted.
    2018-03-20T10:09:22.360+0800 I CONTROL  [initandlisten] ** WARNING: You are running this process as the root user, which is not recommended.
    2018-03-20T10:09:22.360+0800 I CONTROL  [initandlisten]
    2018-03-20T10:09:22.365+0800 I FTDC     [initandlisten] Initializing full-time diagnostic data capture with directory '/home/sunyudong/database/mongodb/diagnostic.data'
    2018-03-20T10:09:22.366+0800 I NETWORK  [thread1] waiting for connections on port 27017
    2018-03-20T10:10:48.106+0800 I CONTROL  [signalProcessingThread] got signal 2 (Interrupt), will terminate after current cmd ends
    2018-03-20T10:10:48.106+0800 I NETWORK  [signalProcessingThread] shutdown: going to close listening sockets...
    2018-03-20T10:10:48.107+0800 I NETWORK  [signalProcessingThread] closing listening socket: 7
    2018-03-20T10:10:48.107+0800 I NETWORK  [signalProcessingThread] closing listening socket: 8
    2018-03-20T10:10:48.107+0800 I NETWORK  [signalProcessingThread] removing socket file: /tmp/mongodb-27017.sock
    2018-03-20T10:10:48.107+0800 I NETWORK  [signalProcessingThread] shutdown: going to flush diaglog...
    2018-03-20T10:10:48.107+0800 I FTDC     [signalProcessingThread] Shutting down full-time diagnostic data capture
    2018-03-20T10:10:48.112+0800 I STORAGE  [signalProcessingThread] WiredTigerKVEngine shutting down
    2018-03-20T10:10:48.502+0800 I STORAGE  [signalProcessingThread] shutdown: removing fs lock...
    2018-03-20T10:10:48.502+0800 I CONTROL  [signalProcessingThread] now exiting
    2018-03-20T10:10:48.502+0800 I CONTROL  [signalProcessingThread] shutting down with code:0
    
  • 执行这个没有反应,卡住不动。

  • 2 楼的方案挺好的。之前我也看到了,感觉挺麻烦,配置好了确实不错。那个帖子有点老,需要跟新 gem。

  • 这个打不开,需要翻墙么?

  • 多谢指正👍 👍 👍

  • 多谢指正,再添加一个 clear_passport! 方法就 OK 了。

  • 不是啊,我就是好奇,想研究一下😌

  • 改成这个样子就可以了:

    module ActiveRecordExtension                                                                              
      def current_passport
        Thread.current[:passport]
      end
    
      def current_passport=(value)
        Thread.current[:passport] = value
      end
    
      def puts_sth
        puts ActiveRecordExtension.current_passport.username
      end
    
      module_function :current_passport, :current_passport=
    end                                                                                                       
    
    ActiveRecord::Base.send :include, ActiveRecordExtension 
    
  • 最后大概是这个样子:

    module ActiveRecordExtension   
      class << self                
        attr_accessor :current_passport 
      end
    
      def puts_sth                 
        puts ActiveRecordExtension.current_passport.username    
      end
    end
    
    ActiveRecord::Base.send :include, ActiveRecordExtension
    

    controller 中添加 before_action :set_current_passport

    def set_current_passport
      ActiveRecordExtension.current_passport = current_passport
    end
    

    感谢各位大神的帮助。

  • 请问为什么不要这样做,会引发什么问题?