宝石kaminari中的分页错误?

时间:2014-01-24 18:16:49

标签: ruby-on-rails ruby ruby-on-rails-4 pagination kaminari

我正在处理rails 4,这是我的步骤: -

  1. gem kaminari --in gemfile
  2. 捆绑安装
  3. @vendors = Vendor.order(:name).page params[:page] vendor_controller.rb) 还试过@vendors=Vendor.order("name").page(params[:page]).per(5)
  4. <% = paginate @vendors %>
  5. index.html.erb

    错误: -

    undefined method `page' for #<ActiveRecord::Relation::ActiveRecord_Relation_Vendor:0x16bec10>
    

    我也试过console

    Vendor.count                 
    a = Vendor.limit(5).count     
    b = a.page(1).per(20).size
    

    错误: -     NOmethoderror undefined method 'page'

    问题: -  哪里出错了??

    由于

2 个答案:

答案 0 :(得分:0)

尝试直接从ActiveRecord类调用页面方法。您在订单后调用它,返回ActiveRecord::Relation个对象。

@vendors = Vendor.page(params[:page]).order(:name)

答案 1 :(得分:0)

我认为这可以解决您的问题:

private void createHotspot2() {
WifiManager wifiManager = (WifiManager) getApplicationContext().getSystemService(Context.WIFI_SERVICE);
WifiConfiguration wifiConfiguration = new WifiConfiguration();
wifiConfiguration.SSID = "MyDummySSID";
wifiConfiguration.preSharedKey = "abcdefgh123";
wifiConfiguration.status = WifiConfiguration.Status.ENABLED;
wifiConfiguration.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.TKIP);
wifiConfiguration.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.CCMP);
wifiConfiguration.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.WPA_PSK);
wifiConfiguration.allowedPairwiseCiphers.set(WifiConfiguration.PairwiseCipher.TKIP);
wifiConfiguration.allowedPairwiseCiphers.set(WifiConfiguration.PairwiseCipher.CCMP);
try {
Method method = wifiManager.getClass().getMethod("setWifiApEnabled", WifiConfiguration.class,
boolean.class);
method.invoke(wifiManager, wifiConfiguration, true);

} catch (Exception e) {
e.printStackTrace();
}
}

在模型中使用:

 vendor.except(:limit, :offset)