开发者

rails searchlogic and will_paginate undefined method `order' for #<WillPaginate::Collection:0x37530ac>

开发者 https://www.devze.com 2023-01-06 12:19 出处:网络
Does anyone have the same problem or a working solution? I get always this error message, here are model, controller and view code

Does anyone have the same problem or a working solution? I get always this error message, here are model, controller and view code

class Profile < ActiveRecord::Base
  cattr_reader :per_page
    @@per_page = 10
end

def index
   @search = Profile.search(params[:search])
    @profiles = @search.paginate(:page => params[:page])
  end

<%= will_paginate order @profiles , :by => :created_at, :as => "name" %>

please help, than开发者_如何学运维ks in advance


You are getting this error because the first parameter that should be passed to the will_paginate view helper method is the collection you want to paginate:

<%= will_paginate @profiles %>

—whereas searchlogic's order helper method returns a link, not a collection. You probably want to do this:

<%= order @profiles, :by => :created_at, :as => 'name' %>
<%= will_paginate @profiles %>

I'm not sure if it will work as intended, I haven't tried it.

0

精彩评论

暂无评论...
验证码 换一张
取 消