小编sin*_*ina的帖子

Rails:阻止will_paginate调用ActiveRelation的#count

当我传递will_paginate一个ActiveRelation时,它总是调用它的#count方法并命中数据库以找出项目的总数.但是这个操作需要时间,我已经缓存并准备好总数.我可以将此预先计算的计数传递给will_paginate并阻止其访问数据库吗?

我尝试了该:count选项,但它作为选项传递给ActiveRecord:

active_relation.paginate(page: 2, per_page: 100, count: total_count)
Run Code Online (Sandbox Code Playgroud)

谢谢!:)

ruby activerecord ruby-on-rails will-paginate

7
推荐指数
1
解决办法
1491
查看次数

如何将脚本文件的结尾读作数据文件(Perl或任何其他语言)

我正在寻找执行以下操作的正确语法(在Perl,Shell或Ruby中):

# variable to access the data lines appended as a file

END_OF_SCRIPT_MARKER

raw data starts here
and it continues.
Run Code Online (Sandbox Code Playgroud)

ruby shell perl

5
推荐指数
1
解决办法
370
查看次数

html5 + js:<input type = file capture = camera>的分辨率或大小

如何通过手机设置从手机上传的照片的最大分辨率或最大尺寸<input type=file capture=camera>

javascript mobile html5 camera ios

5
推荐指数
2
解决办法
1万
查看次数

Ruby和Redis:为订阅设置超时

我想在Redis通道中等待消息最多2秒钟,然后我希望订阅过期/超时并停止阻止我的代码。

redis = Redis.new

redis.subscribe(channel) do |on|
  on.message do |channel, message|
    # ...
  end
end

# This line is never reached if no message is sent to channel :(
Run Code Online (Sandbox Code Playgroud)

我正在使用https://github.com/redis/redis-rb。我在源中进行了搜索,但没有找到订阅的超时选项。

ruby ruby-on-rails publish-subscribe redis

3
推荐指数
1
解决办法
821
查看次数

如何以编程方式设置UITableView的dataSource?

我有一个奇怪的问题.我试图以编程方式将dataSource分配给表.

UITableView使用Interface Builder在ViewController中为它创建了一个和一个IBOutlet.我创建了一个实现的类UITableViewDataSource.我将dataSource我的表设置为dataSource的一个实例.Everything编译并运行正常,直到设置dataSource的行在运行时执行.

错误是,Thread 1: EXC_BAD_ACCESS (code=EXC_i386_GPFLT)class AppDelegate突出显示定义行.

class ViewController: UIViewController {

    @IBOutlet weak var table: UITableView!

    override func viewDidLoad() {
        let ds = MyData()
        table.dataSource = ds // <---- Runtime error
        table.reloadData()
        super.viewDidLoad()
    }
    // ... other methods
}


class MyData: NSObject, UITableViewDataSource {
    func tableView(tableView: UITableView!, numberOfRowsInSection section: Int) -> Int {
        return 5
    }
    func tableView(tableView: UITableView!, cellForRowAtIndexPath indexPath: NSIndexPath!) -> UITableViewCell! {
        let cell = UITableViewCell() …
Run Code Online (Sandbox Code Playgroud)

xcode uitableview ios swift

1
推荐指数
1
解决办法
1万
查看次数