will-paginate

Limit number of pages in will_paginate

六眼飞鱼酱① 提交于 2019-11-30 21:20:36
So, when using Sphinx searches are limited to 1000 results. But, if there are more than 1000 results pagination links generated by will_paginate don't take this into account, and provide links to pages beyond 1000/per_page . Is the an obvious way setting a max pages or something similar? Cheers. I think it's better to submit the parameter :total_entries to method paginate : @posts = Post.paginate(:page => params[:page], :per_page => 30, :total_entries => 1000) will_paginate will generate links only for the number of pages needed to show 1000 results. You can also verify that the requested page

rails3 will_paginate hash object

夙愿已清 提交于 2019-11-30 15:49:55
Looks like will_paginate dosen't support paginating a hash object. I have a list of articles which is basically a collection of yaml files that i want to output on a page. def index @articles = Dir["#{Rails.root}/blog_articles/*.yml"].inject({}) do |h, file| h["#{File.basename(file, '.yml')}"] = YAML::load(File.open(file)) h end end Can anyone suggest me on how to write the pagination for this? Thanks. In your controller: def index @articles = Dir["#{Rails.root}/blog_articles/*.yml"].inject({}) do |h, file| h["#{File.basename(file, '.yml')}"] = YAML::load(File.open(file)) h end # paginate the

Rails 3, will_paginate, random, repeating records, Postgres, setseed failure

与世无争的帅哥 提交于 2019-11-30 15:45:13
问题 I have a database of movies with attributes. I'd like to return a queried batch of those movies in random order to a template with pagination. I'm using will_paginate. I tried the following: ## MoviesController movies = Movie.get_movies(query_string) # a method in Movie model that takes in # a query_string and fetches movies # with user-set params @movies = movies.order('random()').page(params[:page]).per_page(16) This works nicely, except movies are repeated from page to page. Solutions to

Rails 3, will_paginate, random, repeating records, Postgres, setseed failure

泄露秘密 提交于 2019-11-30 14:57:24
I have a database of movies with attributes. I'd like to return a queried batch of those movies in random order to a template with pagination. I'm using will_paginate. I tried the following: ## MoviesController movies = Movie.get_movies(query_string) # a method in Movie model that takes in # a query_string and fetches movies # with user-set params @movies = movies.order('random()').page(params[:page]).per_page(16) This works nicely, except movies are repeated from page to page. Solutions to this problem have been posted here and here . Those links explain that, because the random() seed is

will_paginate with endless Scrolling | Rails4

蓝咒 提交于 2019-11-30 11:05:27
问题 THIS IS THE SOLUTION So i'm using will_paginate / Bootstrap Will Paginate with Endless Scrolling. To get the Pagination working: 1.) In my Controller i updated my index action with @clips = Clip.order("created_at desc").page(params[:page]).per_page(20) 2.) Edit my index view: <%= will_paginate @clips%> DONE Pagination works just fine. To Add Endless scrolling i did the same steps as in my previous Rails 3 App. 1.) Edit my clips.js.coffee jQuery -> $('#clips-masonry').imagesLoaded -> $('#clips

will_paginate undefined method `total_pages'

北城余情 提交于 2019-11-30 10:53:36
问题 What am I missing here? I am using the haml_scaffold generator and the pages work fine with will_paginate. When I start tinkering I end up with this 'total_pages' error and I'm not sure what I am doing that is causing it. Anyone have any insight? I'm using mislav-will_paginate 2.3.11. mike@jauntyjackalope:~/project$ script/console Loading development environment (Rails 2.3.4) >> @locations = Location.find_all_by_city("springfield") => [#<Location id: 3, address: "123 Main St", city:

Rails: Using will_paginate with a complex association find

岁酱吖の 提交于 2019-11-30 07:35:37
I'm encountering a problem with will_paginate while doing a complex find. :photo has_many :tags, :through => :tagships :item has_many :photos :photo belongs_to :item @photos = @item.photos.paginate :page => params[:page], :per_page => 200, :conditions => [ 'tags.id IN (?)', tag_ids], :order => 'created_at DESC', :joins => :tags, :group => "photos.id HAVING COUNT(DISTINCT tags.id) = #{tag_count}" I want to fetch all the photos who have all the tags in the tag_ids array. MySQL's IN usually does "or" searches, but I need "and". I found how to modify IN to mimic "and" behavior here and it works

Limit number of pages in will_paginate

和自甴很熟 提交于 2019-11-30 05:17:35
问题 So, when using Sphinx searches are limited to 1000 results. But, if there are more than 1000 results pagination links generated by will_paginate don't take this into account, and provide links to pages beyond 1000/per_page . Is the an obvious way setting a max pages or something similar? Cheers. 回答1: I think it's better to submit the parameter :total_entries to method paginate : @posts = Post.paginate(:page => params[:page], :per_page => 30, :total_entries => 1000) will_paginate will generate

Will_paginate Plugin on two objects on same page

感情迁移 提交于 2019-11-30 04:58:32
Hello I am using will_paginte plugin on two objects on a same page. Like on stackoverflow. There is a profile page on which there is a pagination on two things QUestions and answers. I am having problem ie:-- when user is clicking on questions pagination page 2. answers page are also updating. The reason is both is sending a post variable ie params[:page] How to change this variable so that only one should be updated. and how to maintain that user should not lose the other page. ie he is on 3rd page of questions and 1st page of answers and now he click on 5th page of the questions the result

will_paginate reporting too many entries and pages

吃可爱长大的小学妹 提交于 2019-11-30 04:55:27
问题 I'm using will_paginate to display data returned from a query that includes both a joins and a select statement. When I paginate the data the number of entries is equal to the number of entries before executing the select statement, even though paginate is being called after the query, and the query contains fewer elements than paginate reports. @sales = Sale.joins(:line_items).where(company_id: company_id, status: ['Complete', 'Voided'], time: (midnight_1..midnight_2)).order('id DESC') puts