kaminari

kaminari undefined method 'page'

送分小仙女□ 提交于 2019-12-05 13:30:51
I am trying to add Kaminari to my Rails app. I have included the gem and this is what my controller looks like: def index if params[:year] if params[:year].size > 0 @songs = Song.where("year like ?", params[:year]).page(params[:page]) elsif params[:artist].size > 0 @songs = Song.where("artist_name like ?", params[:artist]).page(params[:page]) elsif params[:song].size > 0 @songs = Song.where("title like ?", params[:song]).page(params[:page]) end else @songs = Song.first(10).page(params[:page]) end end and then adding <%= paginate @songs %> in my view, the error I am getting is: undefined method

show all results on one page (gem kaminari)

坚强是说给别人听的谎言 提交于 2019-12-05 07:46:34
I have data and they be cut on some pages (10 results per page). code in controller: @messages = Message.order('id DESC').page params[:page] How I can show all results on one page if I want? It similar as 'see all' on page navigate. You can put a very high limit in the per_page option if you still want the paginate helpers to work in your view. @messages = Message.order('id DESC').page params[:page] if params[:all] @messages = @messages.per_page(Message.count) # you can also hardcod' it end 来源: https://stackoverflow.com/questions/11818158/show-all-results-on-one-page-gem-kaminari

Rails 5.0.0.beta1 - Generating an URL from non sanitized request parameters is insecure

左心房为你撑大大i 提交于 2019-12-05 00:27:38
We are upgrading from Rails 4.2.5 to 5.0.0.beta1 When testing we expected to see index views rendered with paginated links as before. But we now get an ArgumentError error page, for example: ArgumentError in Transactions#index /app/views/kaminari/_paginator.html.erb where line #10 raised: <%= paginator.render do -%> Generating an URL from non sanitized request parameters is insecure! Application Trace | Framework Trace | Full Trace app/views/kaminari/_paginator.html.erb:10:in block in _app_views_kaminari__paginator_html_erb___4026289994022119719_69904100316060' app/views/kaminari/_paginator

Rails 3: undefined method `page' for #<Array:0xafd0660>

自古美人都是妖i 提交于 2019-12-04 15:19:24
问题 I can't get past this. I know I've read there isn't a page method for arrays but what do I do? If I run Class.all in the console, it returns #, but if I run Class.all.page(1), I get the above error. Any ideas? 回答1: No Array doesn't have a page method. Looks like you are using kaminari. Class.all returns an array, thus you cannot call page on it. Instead, use Class.page(1) directly. For normal arrays, kaminari has a great helper method: Kaminari.paginate_array([1, 2, 3]).page(2).per(1) 回答2:

find page for given record using kaminari

前提是你 提交于 2019-12-04 13:13:10
Ruby on Rails 3 project. After updating a record we return to the index of all records (not a view of the updated record). The index is paged with Kaminari. How do we return to the page of the index that contains the updated record? Douglas Lovell There is a similar question and answer for Java JPA/Hibernate Finding out the page containing a given record using JPA (Hibernate) that shows the sql needed to get the offset of the record in the index view. Something like SELECT COUNT(*) FROM Model r WHERE r.column < ? ORDER BY r.id The page number will be offset/records_per_page + 1. The question

Kaminari and Capybara conflict

纵然是瞬间 提交于 2019-12-04 10:07:32
I seem to have some sort of conflict between the page method of capybara and the page method of Kaminari. That's what I guessed, anyway, here is the error : Failure/Error: before { sign_in_as user } ActionView::Template::Error: wrong number of arguments (1 for 0) # ./app/models/feed.rb:9:in `microposts' [Rest of the backtrace] The code sample : class Feed def microposts(opts = { urgent: false }) urgent = opts[:urgent] p Microposts.where(id: 1).page # <Capybara::Session> p Microposts.where(id: 1).page(1) # Error end end If I remove the pagination, the test works fine. I don't understand how

Rails caching: Expiring multiple pages for one action

 ̄綄美尐妖づ 提交于 2019-12-04 05:25:39
I've set up action caching (with sweepers, but I guess that's irrelevant here) in my app, and so far it works great except for one thing: I use Kaminari for pagination, and thus when I execute expire_action on my action it only expires the first page. As I know caching won't work when using the query string for specifying the page, I've set up a route so the pages are appended to the end of the url (for example /people/123/page/2). I'll add more info to this post if necessary, but I'm guessing there is something obvious I'm missing here, so: Anyone know how to expire the rest of my pages? I'm

Reverse pagination with kaminari

感情迁移 提交于 2019-12-03 23:32:15
I want to create pagination for a messaging system in which the first page shown contains the oldest messages, with subsequent pages showing newer messages. For example, if normal pagination for {a,b,c,d,e,f,g,h,i} with 3 per page is: {a,b,c}, {d,e,f}, {g,h,i} Then reverse pagination would be: {g,h,i}, {d,e,f}, {a,b,c} I plan to prepend the pages so the result is the same as normal pagination, only starting from the last page. Is this possible with kaminari ? There's a good example repo on Github called reverse_kaminari on github. It suggests an implementation along these lines (Source) .

Ruby/Rails - kaminari undefined method pagination errors

只愿长相守 提交于 2019-12-03 17:28:58
I'm not sure what I did, but kaminari has started acting weird in my app. In my controller: @producers = Producer.order(:name).page(params[:page]) view: <%= paginate @producers %> results in: undefined method `num_pages' for #<ActiveRecord::Relation:0x000001026e6308> If I add .per in my controller: @producers = Producer.order(:name).page(params[:page]).per(25) I get undefined local variable or method `per' for #<ActiveRecord::Relation:0x0000010928ef60> Finally, strangely, if I move my .order(:name) to the end, it works: @producers = Producer.page(params[:page]).order(:name) I'm guessing some

Rails 3: undefined method `page' for #<Array:0xafd0660>

一世执手 提交于 2019-12-03 10:33:20
I can't get past this. I know I've read there isn't a page method for arrays but what do I do? If I run Class.all in the console, it returns #, but if I run Class.all.page(1), I get the above error. Any ideas? No Array doesn't have a page method. Looks like you are using kaminari. Class.all returns an array, thus you cannot call page on it. Instead, use Class.page(1) directly. For normal arrays, kaminari has a great helper method: Kaminari.paginate_array([1, 2, 3]).page(2).per(1) Kaminari now has a method for paginating arrays, so you can do something like this in your controller: myarray =